Cannot create DbSet for entity type 'User' since it is of type 'User' but the generic type provided is of type 'User'
here is my code in repository
Here is snippet in EFRepository.cs
protected FocusOnDbContext Context => Services.GetRequiredService<FocusOnDbContext>();
protected DbSet<TEntity> GetSet() => Context.Set<TEntity>();
public override TEntity? Add(TEntity entity)
{
if ( entity is null )
{
throw new ArgumentNullException(nameof(entity));
}
GetSet().Add(entity);//throws Cannot create DbSet for entity type 'User' since it is of type 'User' but the generic type provided is of type 'User'
return entity;
}
in unit test
var entityToAdd = _repository.Add(new User()
{
Name = "test",
Age = 12
});
await _unitOfWork.CommitAsync();
It was never happened since I upgraded to EFCore 7.0 with same code
EF Core version: Database provider: Microsoft.EntityFrameworkCore.InMemory Target framework: .NET 7 Operating system: Windows 10 IDE: Visual Studio 2022 17.4
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.