This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
im sorry if this is obvious but its driving me crazy.
How do I get the child object that has the minimum, date field say?
I dont want the min VALUE of that object but THE object itself.
Thanks in advance
|
|
|
Let me restate the problem so as to make sure I've understood it. You have a parent entity, with a child collection. Given a parent entity, you want to obtain the child entity with the minimum date. Is that correct? If so, there are a couple of possible approaches. Firstly, you could just use LINQ to Objects on the child collection to get the element with the minimum date. Either of the following should work (not tested): Child earliest = parent.Children.OrderBy(c => c.Date).First(); Secondly, you could query the database for the child entity: Child earliest = (from c in uow.Children (or the equivalent using the core API -- see Query.Order and Query.Page) Note you are querying for a Child directly, not going through the Parent.Children collection. This is therefore more efficient if the children are not already loaded (and you do not plan to load them). |
|
|
**slaps forehead**
cheers thx for that.
and there i was trying to use .Min() etc...
|
|