c# - Select from two entities with LINQ -


i have issues wrapping head around .include in linq. i'd appreciate lot if show me query achieve this:

i have 2 entities, user , validation (which serie of validation codes) . related in ef5 1:*. i'm trying user object , eager load validations collection.

at moment, i'm doing (cx being context inside using block):

var user = cx.users             .where(u => u.userguid.equals(userguid))             .firstordefault();  if (user == null) {     return 0; }  var validation = cx.validations             .where(v => v.code.equals(code))             .where(v => v.userid.equals(user.userid))             .firstordefault(); 

but how achieve in 1 query can use

user.validations.firstordefault(); 

without getting error , getting validations satisfy validation.code == code test?

thanks (i know i'm sounding confused that's because am).

did try this:

var validation = cx.validations.where(v=>v.code==code &&                                          cx.users.any(u=>u.userid==v.userid &&                                                           u.userguid==userguid)                                       ).firstordefault(); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -