开发者

How do I check if a Linq to SQL entity has grandchildren?

How can I find out if a Linq to SQL entity has grandchildren or not?

Pseudo-code below:

Return From p In dc.Processes Where p.Signers.Count > 0 and p.Signers.Signatures.Count开发者_JAVA百科 > 0

Obviously I can't run the code above but I need to make sure that all the returning Processes have at least one Signer and that all of those Signers have at least one Signature.

TIA!


Something like this should work.

... VB.Net ...

Return From p In dc.Processes _
       Where p.Signers.Any(Function(s) s.Signatures.Any()) _
       Select p

... C# ...

return  from p in dc.Processes
        where p.Signers.Any(s=>s.Signatures.Any())
        select p;


You may have to do a sub select if your tables are many to many relationship. Something like this should work in this instance

Return (From p In dc.Processes Where p.Signers.Count > 0 And (from t in p.Signers where t.signatures.count) > 0)


The following code is C#, but it will do the trick:

 from p in db.Processes
 where p.Signers.Any(s => s.Signatures.Any())
 select p
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜