Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

c# - Entity Framework Core - Lazy Loading

Bowing to my Visual Studios request, I started my latest project using Entity Framework Core (1.0.1)

So writing my database models as I always have using the 'virtual' specifier to enable lazy loading for a List. Though when loading the parent table it appears that the child list never loads.

Parent Model

public class Events
{
    [Key]

    public int EventID { get; set; }
    public string EventName { get; set; }
    public virtual List<EventInclusions> EventInclusions { get; set; }
}

Child Model

public class EventInclusions
{
    [Key]
    public int EventIncSubID { get; set; }
    public string InclusionName { get; set; }
    public string InclusionDesc { get; set; }
    public Boolean InclusionActive { get; set; }

}

Adding new records to these tables seems to work as I am used to where I can nest the EventInclusions records as a List inside the Events record.

Though when I query this table

_context.Events.Where(e => e.EventName == "Test")

The Issue

EventInclusions will return a null value regardless of the data behind the scenes.

After reading a bit I am getting the feeling this is a change between EF6 which I normally use and EF Core

I could use some help in either making a blanket Lazy Loading on statement or figuring out the new format for specifying Lazy Loading.

Caz

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Lazy loading is now available on EF Core 2.1 and here is link to the relevant docs:

https://docs.microsoft.com/en-us/ef/core/querying/related-data#lazy-loading


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...