Home > Net >  How to convert the following SQL statement to linq statement
How to convert the following SQL statement to linq statement

Time:09-19

 select 
TD. TD001 order sheet no,
TD TD002 order number,
TD TD003 order serial number,
TD. TD004 article number,
TD TD005 name,
TD TD006 specifications,
TD TD007 warehouse,
TC TC004 customer number,
TC TC012 customer PO,
TC TC003 order date,
TH. TH008 delivery quantity,
MC. MC007 inventory quantity
The from BW_COPTD AS TD
LEFT the JOIN BW_INVMC AS MC ON MC. MC001=TD. TD004 AND MC. MC002=TD. TD007
Left the join BW_COPTC as TC ON TC TC001=TD. TD001 AND TD. TD002=TC TC002
Left the join BW_COPTH AS TH ON TD. TD001=TH. TH001 AND TD. TD002=TH. TH002 AND TD. TD003=TH. TH003

CodePudding user response:

You know about the defaultIfEmpty
https://www.cnblogs.com/sjqq/p/8385326.html

CodePudding user response:

To clarify first table, the relationship between the linq several keyword syntax similar to SQL,

CodePudding user response:

This is just simple ` LEFT JOIN ` for LINQ,
Check the samples on the MSDN: https://docs.microsoft.com/en-us/dotnet/csharp/linq/perform-left-outer-joins

CodePudding user response:

The
reference rabbit party - inspector reply: 3/f
This is just simple ` LEFT JOIN ` for LINQ,
Check the samples on the MSDN: https://docs.microsoft.com/en-us/dotnet/csharp/linq/perform-left-outer-joins


Or yep. Linq does not support joinning with multi - condition, and you should use the composite type as the key.

CodePudding user response:

The from of TD in BW_COPTD
Join the MC in BW_INVMC ON new {MC001=MC. MC001, MC002=MC MC002} equals new {MC001=TD TD004, MC002=TD. TD007} into MCJoin
Join the TC in BW_COPTC on new {TC001=TC TC001, TD001=TD. TD001} equals new {TC001=TD. TD002 TD001=TC TC002}
The join TH in BW_COPTH on new {TD001=TD. TD001 TD002=TD. TD002, TD003=TD. TD003} equals new {TD001=TH. TH001, TD002=TH. TH002, TD003=TH. TH003}
From the MC in MCJoin DefaultIfEmpty ()

CodePudding user response:

The from of TD in BW_COPTD
Join the MC in BW_INVMC ON new {MC001=MC. MC001, MC002=MC MC002} equals new {MC001=TD TD004, MC002=TD. TD007} into MCJoin
Join the TC in BW_COPTC on new {TC001=TC TC001, TD001=TD. TD001} equals new {TC001=TD. TD002 TD001=TC TC002}
The join TH in BW_COPTH on new {TD001=TD. TD001 TD002=TD. TD002, TD003=TD. TD003} equals new {TD001=TH. TH001, TD002=TH. TH002, TD003=TH. TH003}
From the MC in MCJoin. DefaultIfEmpty ()
Select new {
Don't order single=TD TD001,
.
}
  •  Tags:  
  • LINQ
  • Related