2013-09-24 2 views
-5
내부 이하로 변환하는 방법

는 다음과 같이보고 바람 것이다 쿼리 (하지만, 명심 당신이거야 LINQ 문LINQ의 내부 조인?

SELECT ca.[CUS_ADDRESS_ID] 
    ,ca.MASTER_CUSTOMER_ID  
    ,ca.[ADDRESS_1]  
    ,[CITY] 
    ,[STATE] 
    ,COUNTRY_CODE 
    ,cad.ADDRESS_TYPE_CODE 
    ,cad.ADDRESS_STATUS_CODE 
    inner join [CUS_ADDRESS_DETAIL] cad on ca.CUS_ADDRESS_ID = cad.CUS_ADDRESS_ID and cad.PRIORITY_SEQ = 0 
    where ca.CUSTOMER_ID = '0000026' 

에 SQL 문을 가입하고

public class Location 
{  
    public string CustomerNumber { get; set; } 
    public string City { get; set; } 
    public string State { get; set; } 
    public string Country { get; set; } 
    public string AddressLocCode { get; set; } 
    public string AddressStatus { get; set; } 
} 
+1

http://stackoverflow.com/questions/37324/what-is-the-syntax-for-an-inner-join- in-linq-to-sql? rq = 1 –

답변

0

에 할당 그들이 조금 엉망이 보이는 때문에) 일치하도록 필드 이름을 변경해야합니다 :

var locations = from c in Customers 
       join ca in CustomerAddresses 
       on new { c.CustomerAddressId, 0 } 
        equals new { ca.CustomerAddressId, ca.PrioritySeq } 
       select new Location 
       { 
        CustomerNumber = c.MasterCustomerId, 
        City = ca.City, 
        State = ca.State, 
        Country = ca.Country, 
        AddressLocCode = ca.AddressLocCode, 
        AddressStatus = ca.AddressStatus 
       }; 
+0

ca.CUS_ADDRESS_ID = cad.CUS_ADDRESS_ID 및 cad.PRIORITY_SEQ = 0'에 '내부 조인 [CUS_ADDRESS_DETAIL] cad를 추가하려는 경우. 이 작업을 수행하는 방법? – James123

+0

@ James123 - 업데이트. –

+0

의 "해당 형식 인수를 쿼리에서 유추 할 수 없습니다"라고 표시됩니다 .cadidates는 system.collections.generic.IEnumerable입니다. James123