ef code first - Entity Framework Projection: Materialize Additional List -


Looking at the given (simplified) object model below, give me the schedule object given to the Person , but only load the class es taking that person.

I am using a projection and it works fine (excepting the EF profiler, there is a lot of complaining about joining).

Now let me person. There is a new requirement to also load fineness . I expected that the comment-out code will be // FunFacts = s.Person.FunFacts, however, it is not.

I can accomplish my goal by reaching the schedule.FunFacts while the context is still active. However, it creates an extra round trip to the database.

Question : Can I modify my launch to return the idle without any support to the schedule.FunFacts via proxy ?

Object Model (Simplified)

  Public category schedule {Public Entry ID (Receive; Set;} Public Person {Received} ;} Public list & lt; Class & gt; Classes {receive; set;}} Public class class {public id id (get; set;} public int name {get; set;}} public class insurance (Received); set;} public schedule schedule {get; set;} public notice  Phoenix {get; set;}} Public class FunFact {Public Ent ID (get; set;} public string name {get} set;} public string text {get; set;}}   

Materialization code

 5, 7, 11}; Var schedule = (from sfilter (from ctx.Schedules) where s.Person.Id == desired PersonId new {Schedule = s, Person = s.Person, // FunFacts = s.Person. Choose FunFacts, Class = c from the S Classes, where select Class Ideas.Select (CID) c}). Assum Nniy () Select sFilter.Schedule). FirstOrDefault ();    

It is found that FunFacts was actually selected Is not just related to the example of the schedule Inspired by

, I solved the problem by making the following changes:

  var scheduleProjection = (from Ctx.Schedules where s.Person.Id == desired PersonId New {Schedule = s, person = s.Person, FunFacts = s.Person.FunFacts, class = c to s.Classes where classIds.Contains (c. Id) select c}) .FirstOrDefault (); Var Schedule = Schedule Projection Schedule; Schedule.FunFacts = Schedule Publishing.form;    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -