Entity Framework does not require lazy loading Complex Type

I have a problem with Lazy Loading in the Entity Framework. I have some members who check regularly, so the following (simplified) model:

public class Member { public int memberId { get; set; } public string name{ get; set; } } class CheckIn { public int checkInId { get; set; } public virtual Member member { get; set; } public DateTime timestamp { get; set; } } 

and in the context of:

 public DbSet<Member> leden { get; set; } public DbSet<CheckIn> checkins { get; set; } 

So, I checked that the member property is full in the database (it contains memberId).

however, when I try to get all the checks:

 IQueryable<CheckIn> Checkins = db.checkins; 

it collects all the checks, but everywhere the member property is null. I tried to install

 db.Configuration.LazyLoadingEnabled= true; 

but it did not help. Anyone with an idea why this is not working?

+4
source share
2 answers

Lazy loading of complex types is not possible:
Note that EF always initializes property values ​​to a Complex of type immediately when an instance of an object that contains a complex object . EF does not support lazy loading for complex types (the same restriction exists if you want to have lazy loading for scalar properties of an object). This is inconvenient when we have to deal with potentially large values ​​(for example, a property of type byte[] in the complex type Address, which was mapped to VARBINARY in the Users table and contains an image of the location described in the address.).

Sourse of information

0
source

For lazy loading you need to use the virtual . In your model:

 class CheckIn { public virtual Member member { get; set; } } 
-one
source

Source: https://habr.com/ru/post/1498411/


All Articles