如何将下面的内部联接SQL语句转换为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'
并分配给
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; }
}
答案 0 :(得分: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
};