开发者

Help with a algorithm in linq to resolve a query

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.


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)
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜