tags:

views:

46

answers:

1

I have been some time thinking how to resolve this problem, but out of ideas i prefer expose it for help.

I have 2 tables (linq to sql) A and B, A have a many relation with B, so A have a property EntitySet of B

 A have the following properties:
  CreateDate (Datetime)
  ModificateDate (Datetime)
  Bs (EntitySet<B>)

 B have the following properties:
  CreateDate (Datetime)
  ModificateDate (Datetime)

All that i want is return a ordered collection of A by the Max date between :

 A.CreateDate, 
 A.ModificateDate, 
 The Max B.CreateDate of all B in A
 The Max B.ModificateDate of all B in A

if i someone need a little example, just ask for it.

A: 

This should do the trick:

from a in db.As
select new
{
    a.CreateDate, 
    a.ModificateDate, 
    MaxCreateDate = a.Bs.Max(b => b.CreateDate), 
    MaxModificateDate =
        a.Bs.Max(b => b.ModificateDate)
}
Steven
Yes, this query resolve the part of get all the date, and select the max date will be more easy, just miss the part of order A for this maxdate
Deumber