Off the top of my head: var q = from c in Container from r in c. Records group r by r.RecordType. RecordType_Id into g select new { Container = c, RecordType_Id = g.
Key, Records = from gr in g let maxDate = g. Max(d => d. Date) where gr.
Date == maxDate select gr }.
Line 6 is saying the c symbol cannot be resolved. However, I'm not sure that ending up with an anonymous type is the correct solution. I need EF to be returning its tracked objects of Container as per normal.
Except that each Container's "Records" collection is restricted to only include the most recent entries of each type. – NathanE May 24 at 13:16 Maybe I'm going about this the wrong way. Maybe I should be exposing the Container objects as they come.
But make the Records collection be lazy loaded so that the consumer can append their deferred query logic to do the 'most recent records only' restriction. – NathanE May 24 at 13:18 You can work around the unresolved symbol by including it in the grouping. Don't let the anonymous type throw you off -- the Records property is a list of entities, just like you asked.
– Craig Stuntz May 24 at 13:33 I think possibly my question was badly worded. It is my Container repository. Therefore it needs to be returning fully initialized Container objects.
The Record objects must be filtered to only be the most recent ones, for each Container object. – NathanE May 24 at 13:52 You can return Container objects, if you want. But if you're asking to "filter" the Container.
Records, then they aren't fully initialized, because real containers have more records. – Craig Stuntz May 24 at 13:55.
Try using LinqPad, it helps you test linq queries easily. Even against an existing EF model (which is in your project). Visit linqpad.net.
I have two entities, assume they are called Container and Record. They have a master-child relationship: a 'container' can hold many records. The Record entity does not have any navigation properties that back reference the Container.
I am writing a LINQ query for my repository that will retrieve ONLY the records for a container that have the most recent date for each RecordType_Id. All older records should be ignored. So if a container has say 5 records, one for each RecordType_Id, with the date 24/May/2011.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.