Ich untersuche, wie man API in .NET 8 schreibe. Wie löste ich es? Todoapidb.data.todoItemService ':
Diener nicht in der Lage, den Typ' Microsoft.EntityFrameworkcore.dbset`1 [toDoapidb.models.todoItem] '
während zu aktivieren, um' todoapidb.data. /todoapidb.data zu aktivieren ''. /> < /blockquote>
:
Code: Select all
builder.Services.AddScoped();
< /code>
ITodoItemsService.cs
:
Code: Select all
public interface ITodoItemsService
{
List? GetAbunch(string[] myAnimals);
}
< /code>
TodoItemsService.cs
:
public class TodoItemsService: ITodoItemsService
{
private readonly DbSet _todoItems;
public TodoItemsService(DbSet todoItems)
{
_todoItems = todoItems;
}
List? ITodoItemsService.GetAbunch(string[] myAnimals)
{
var animals = _todoItems.Where(i => myAnimals.Contains(i.Name))
.ToList();
return animals;
}
}
< /code>
GitHub code of the API application.
Screenshot of the error in Visual Studio:

Ich untersuche, wie man API in .NET 8 schreibe. Wie löste ich es? Todoapidb.data.todoItemService ':
Diener nicht in der Lage, den Typ' Microsoft.EntityFrameworkcore.dbset`1 [toDoapidb.models.todoItem] '
während zu aktivieren, um' todoapidb.data. /todoapidb.data zu aktivieren ''. /> < /blockquote>
[code]Program.cs[/code]:
[code]builder.Services.AddScoped();
< /code>
ITodoItemsService.cs[/code]:
[code]public interface ITodoItemsService
{
List? GetAbunch(string[] myAnimals);
}
< /code>
TodoItemsService.cs[/code]:
public class TodoItemsService: ITodoItemsService
{
private readonly DbSet _todoItems;
public TodoItemsService(DbSet todoItems)
{
_todoItems = todoItems;
}
List? ITodoItemsService.GetAbunch(string[] myAnimals)
{
var animals = _todoItems.Where(i => myAnimals.Contains(i.Name))
.ToList();
return animals;
}
}
< /code>
GitHub code of the API application.
Screenshot of the error in Visual Studio:
[img]https://i.sstatic.net/4HuslbLj.png[/img]