2

I am new to linq... and I am wondering if I am doing it right..

Here's my code...

var result = from a in ctx.ItemReceipts
             join b in ctx.ItemReceiptStatusTypes on a.Status equals b.ItemReceiptStatusTypeID
             join c in ctx.PurchaseOrders on a.ReferenceID equals c.PurchaseOrderID
             into leftJoinItemReceipts 
             from d in leftJoinItemReceipts.DefaultIfEmpty()
             where a.ItemReceiptID.Equals(ItemReceiptID)
             select new
             {
                 CItemReceiptID = a.ItemReceiptID,
                 CTransactionNumber = a.TransactionNumber,
                 CRemarks = a.Remarks,
                 CStatus = a.Status,
                 CStatusType = b.Description,
                 CReferenceID = a.ReferenceID,
                 CReferenceTypeID = a.ReferenceTypeID,
                 CTransactionDate = a.TransactionDate,
                 CDateReceived = a.DateReceived,
                 CTotalCost = a.TotalCost,
                 CPONumber = d.PONumber                     
             };

It runs perfectly... but I really can't understand the into part.. I dunno if it's really a left join but gives me the data that I want... it gives me all data in itemreceipts even though they don't have something in common with PurchaseOrder....

I need explanation... better a comparison between mysql and linq...

Sayse
  • 42,633
  • 14
  • 77
  • 146
Sam Teng Wong
  • 2,379
  • 5
  • 34
  • 56

1 Answers1

0
from a in ctx.ItemReceipts
join b in ctx.ItemReceiptStatusTypes on a.Status equals b.ItemReceiptStatusTypeID
into leftJoinItemReceipts 
from d in leftJoinItemReceipts.DefaultIfEmpty()
join c in ctx.PurchaseOrders on d.ReferenceID equals c.PurchaseOrderID

This will do a left join on ItemReceipts and ItemReceiptStatusTypes and then a inner join with PurchaseOrders

Nambirajan S
  • 201
  • 1
  • 6