Tuesday, 15 April 2014

sql - C# Linq expression for nested left join -


I'm looking to format nested left participants in a leaked expression. I have downloaded LINQPad4, but SQL does not have the ability to translate into Linux.

I do not understand how to join nested left I have tried to tamper with the expression 'these' clauses.


Link Expression

  Join the entity relationship in Client from Client EGUID er.ParentID connects the thief in the contact equals on er.ChildID con.EGUID er.EGUID on EntityRelationships equals erEmail.ParentID in erIfAny R join erEmail erIfAny.DefaultIfEmpty (in) equals equals r.ChildID EA joining EA EmailAddresses. EGUID equals r.ID eaDefault.RelationshipID joining eaDefault in EntityDefaultValues ​​where cli.ClientID == choose 6 new {ContactID = con.ContactID, ContactLastName = con.ContactLastName, ContactFirstName = con.ContactFirstName, ContactTitle = Con.ContactTitle, EmailAddress = EA}).). ()  

Production of the following SQL statement

  DECLARE @ p0 Int = 6 SELECT DISTINCT con. *, Ea. * Join Clients from AS Cli INNER as EntityRelationships to meet cli.eGUID = er.ParentID as INNER contacts on AS. CHILDID = con.iGUID LE FT external er.eGUID = erEmail.ParentID EntityRelationships include erEmail inner EmailAddresses EA on erEmail.ChildID = ea.eGUID erEmail.ID joining as internal EntityDefaultValues ​​eaDefault = eaDefault.RelationshipID Where the cli.ClientID = @ p0 >  

However, after being wrapped in the left side of the left, both internal joins are required.

  DECLARE @ p0 Choose int = 6 DISTINCT con *, EA * Customers as CLI Insider on cli.eGUID = er.ParentID on EntityRelationships interiors include Er er.ChildID = con.eGUID Left external thief involved in contact as both the erEmail inner EmailAddresses consists of EntityRelationships from as well as erEmail.ChildID EA = EA Join .eGUID insider on er.eGUID = erEmail.ParentID where ClikClientID = P0 @ EntityDefaultValues ​​ErEmailkID = on as eaDefault eaDefault.RelationshipID which  

What should my LINQ expression look like?


Edit:

Did not know that I can do this, but I have just finished writing interval SQL.

  var quar y = db.Database.SqlQuery & lt; ContactViewModel & gt; ("Different Thief Selection *, ea.Value as an EmailAddress." + "CLI as Clients" + "Joining the Contact" as EntityRelationships er joining in cli.eGUID = er.ParentID "Er.ChildID = con.eGUID" + "Join the EntityRelationships as the" erEmail "Thief" + "EmailAddresses as EEmail.ChildID = ea.eGUID on EA" erEmail.ID " = eaDefault.RelationshipID "EntityDefaultValues ​​er.eGUID = erEmail.ParentID" joining as eaDefault a + "+" where cli.ClientID = "+ cID.ToString () + con.ContactLlastName by" + "command, Con.ContactFirstName ");  

Trying to get LINQ code for people to match SQL is a very common mistake they used to do Since SQL is limited to a flat result set, while object-oriented codes can represent rich hierarchical data, then it is very possible that what you want actually can be better prepared in a LINQ query Is that Not stop thinking about the SQL side of things.

Let me make sure that what you are going for here but often does not end up looking like an object with one other on one joining the left outer LINQ Your properties:

 in customers from  CLI where cli.ClientID == 6 cli.EGUID joining the ER in EntityRelationships is equal to joining the thief in contact on er.ParentID er.ChildID. Is con.EGUID new selection {equals ContactID = con.ContactID, ContactLastName = con.ContactLastName, ContactFirstName = Con.ContactFirstName, ContactTitle = con.ContactTitle, EntityRelationships where er.EGUID == erEmail.ParentID EmailAddresses is included in the EA when r.ChildID EA equals eEmail's email =. EGUID where EntityDefaultValues.Any (eaDefault = & gt; RID == eaDefault.RelationshipID select ea}  

No comments:

Post a Comment