반응형
http://ngmaster.mooo.com/ngmaster/xe/index.php?document_srl=4801&mid=COMMUNITY_Q_AND_A
벤더와 주문번호를 조인 걸기 위한 방법입니다. 예제로 사용된 Database는 MS에서 샘플로 배포하고 있는 AdventureWorks입니다. 설치 방법은 [이곳]에서 확인할 수 있습니다.
Linq
1 2 3 4 5 6 | var orders = from v in dataContext.Vendors join o in dataContext.PurchaseOrderHeaders on v.BusinessEntityID equals o.VendorID select new { v.BusinessEntityID, v.Name, o.Freight }; this .orderList.DataSource = orders.ToArray(); |
위의 조인을 람다식으로 표현하면 아래와 같습니다.
Lanbda
1 2 3 4 | this .orderList.DataSource = dataContext.Vendors.Join(dataContext.PurchaseOrderHeaders, v => new ( v.BusinessEntityID, v.EmployeeID }, o => new { o.VendorID, o.EmployeeID }, (v, o) => new { v.BusinessEntityID, v.Name, o.Freight }).ToArray(); |
Join에 필요한 컬럼이 2개 이상이라면 아래와 같이 처리합니다. 이 방법은 GroupBy에도 동일하게 적용됩니다.
Linq
1 2 3 4 5 6 | var orders = from v in dataContext.Vendors join o in dataContext.PurchaseOrderHeaders on new { v.BusinessEntityID, v.EmployeeID } equals new { o.VendorID, o.EmployeeID } select new { v.BusinessEntityID, v.Name, o.Freight }; this .orderList.DataSource = orders.ToArray(); |
위의 조인을 람다식으로 표현하면 아래와 같습니다.
Lanbda
1 2 3 4 | this .orderList.DataSource = dataContext.Vendors.Join(dataContext.PurchaseOrderHeaders, v => v.BusinessEntityID, o => o.VendorID, (v, o) => new { v.BusinessEntityID, v.Name, o.Freight }).ToArray(); |
반응형
댓글