I have a table that looks like:
Key Date … Name … Status …
(ID) May …
(ID) May …
(ID) May …
(ID) June …
(ID) June …
(ID) June …
(ID) Jul …
(ID) Jul …
What I need is to take the entities in bold as that is the overall property for the set.
So it looks like:
(ID) May …
(ID) June …
(ID) Jul …
The Entity Set is retrieved with:
var status = from a in ObjectContext.InspectionReadings
where a.InspectionID == new Guid(inspID)
&& a.DateTaken > before
&& a.DateTaken <= DateTime.Now
orderby a.DateTaken descending, a.Status descending
select a;
Now i just need to filter out the ones I don’t want.
How can I do this?
Thank you
You can accomplish this with a
GroupByas well as a call toFirst.For example, given your original query,
status, you can do:Note that LINQ-to-Entities might not be able to properly group the data, based on requirements for the select clause in your underlying database.
With that, you can always call
AsEnumerableto force the query to occur on objects in memory:One caveat, you should probably order each group depending on which item you want to be returned (if they aren’t already ordered correctly).