-6

How to convert below inner join SQL statement into LINQ statement

 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'

and assign to

 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; }
}
James123
  • 11,184
  • 66
  • 189
  • 343

1 Answers1

0

The query would wind up looking something like this (keep in mind, though, that you'll have to change your field names to match since they look a little mangled):

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
                };
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
  • If I want add ` inner join [CUS_ADDRESS_DETAIL] cad on ca.CUS_ADDRESS_ID = cad.CUS_ADDRESS_ID and cad.PRIORITY_SEQ = 0`. How to do this? – James123 Sep 24 '13 at 15:15
  • its says "The Type arguments cannot be inferred from the query" cadidates are system.collections.generic.IEnumerable join – James123 Sep 24 '13 at 15:27