Suppose we have 2 types, mapped to a Database via EF 4.
Schedule 1.....1 Visit
Also, we have third custom view type
public class ScheduleView
{
public Schedule Schedule { get; set; }
public Visit Visit { get; set; }
}
So we can write the join query
var query = Context.Schedule.Join(Context.Visit
,/*Schedule join key definition*/,/*Visit join key definition*/,
(scheduleView, visit) => new ScheduleView {Schedule = scheduleView, Visit = visit})
The problem is that I need to load also Patient
property of Visit
type. But when I write
query = (query as ObjectQuery<ScheduleView>).Include("Visit.Patient");
I receive a runtime error
Unable to cast the type 'System.Linq.IQueryable
1' to type 'System.Data.Objects.ObjectQuery
1'. LINQ to Entities only supports casting Entity Data Model primitive types.
So, the question is - how to force query to include something within my custom type?