EDIT: This question has been closed because someone thought it is a duplicate for another question on SO. It is not. The duplicate question, and all of the (old) docs I've found, deal with adding virtual
to entity class navigation properties to enable lazy loading. This question is about what happens if I add virtual to the DbContext DbSet<> property.
We now return you to the original post:
I'm looking for definitive guidance about the effect of adding virtual
to my existing DbSet
DbContext properties in EF Core 7 or 8.
This came about because I want to use the Moq.EntityFrameworkCore
NuGet package to mock my DbContext, which requires my DbSet<TableName>
statements to be virtual
.
EDIT: The above statement is the intended, complete question. The following is the original version of the question, which includes my observation that the virtual
keyword in question has something to do with "lazy loading". I now know that is incorrect, and I understand that my question (above) implies an additional question: Why can my DbSet and my entity classes have virtual navigation properties and DbSet properties? Where is the concrete implementation of these virtual properties? The answer explains that very nicely.
I am using EF Core 8. Earlier versions of EF Core provided lazy loading features related to decorating the DbSet<TableName>
statements in the DbContext class with the virtual
keyword, for example:
public virtual DbSet<PatientTestEntity> PatientTestEntities { get; set; }
The current documentation makes no mention of this (as far as I can tell).
I'm looking for definitive guidance about the effect of adding virtual
to my existing DbSet
DbContext properties in EF Core 7 or 8.
This all came about because I want to use the Moq.EntityFrameworkCore
NuGet package to mock my DbContext, which requires my DbSet<TableName>
statements to be virtual
.