Entity Framework: how to do correct “Include” on custom type

后端 未结 2 1439
春和景丽
春和景丽 2021-01-19 17:22

Suppose we have 2 types, mapped to a Database via EF 4.

Schedule 1.....1 Visit

Also, we have third custom view type

public          


        
2条回答
  •  长发绾君心
    2021-01-19 17:46

    Finally, developed some ugly workaround - introduced new member in custom type and explicitly queried for it.

    public class ScheduleView
    {
        public Schedule Schedule { get; set; }
        public Visit Visit { get; set; }
        **public Patient Patient{ get; set; }**
    }
    
        var query = Context.Schedule.Join(Context.Visit
        ,/*Schedule join key definition*/,/*Visit join key definition*/,
        (scheduleView, visit) => new ScheduleView 
    {Schedule = scheduleView, Visit = visit, **Patient = visit.Patient**})
    

    Now I have Patient loading properly in my custom type. Amusing, but when I investigate ScheduleView.Visiting.Patient after introducing ScheduleView.Patient I found it also loaded. Cant get the EF logic in this case. And dunno how to force loading ScheduleView.Visiting.Patient without having to load useless ScheduleView.Patient :(

提交回复
热议问题