linq - Get data from multiple table using Entity Framework 5 -
in database, have 4 tables relationship this:
inspection --> correspondence --> correspondenceto, user
now, when inspectionid
equals something, want subject
, correspondencetype
, sentdate
correspondence
, displayname
user
, firstname
, lastname
correspondenceto
. write code this:
var result = in context.inspections join correspondence in context.correspondences on i.id equals correspondence.inspectionid join correspondenceto in context.correspondencetoes on correspondence.id equals correspondenceto.correspondenceid join user in context.users on correspondence.senderuserid equals user.id i.id == inspectionid select new { subject = correspondence.subject, correspondencetype = correspondence.correspondencetype, sentdate = correspondence.sentdate, sender = user.displayname, receiver = new { correspondenceto.firstname, correspondenceto.lastname } }; return json(result);
what's wrong code? how see result in visual studio 2012? besides, want left join tables above. should do? if want use include
instead of join
, how that?
Comments
Post a Comment