0

basically i want to check DestinationCustomerList with SA_CUSTOMER_ALLOC if any record found based on customerId and fieldId then return priority else priority = 1 , so i am using left outer join with entity but it's not working properly(returning only matching record and if SA_CUSTOMER_ALLOC doesn't have any record throwing "Object referenece error" how to handle this.

  var Query = (from p in DestinationCustomerList
                     join p2 in Context.SA_CUSTOMER_ALLOC on new { f1 = p.CustomerId, f2 = p.FieldId } equals new { f1 = p2.CUSTOMER_ID, f2 = p2.FIELD_ID }
                       into temp
                     from x in temp.DefaultIfEmpty()
                     where x.TAG_ID == TagId && x.REGION_ID == RegionId
                     select new { p.CustomerId,p.FieldId, Priority = x == null ? 1 : x.PRIORITY }).ToList();
user1818042
  • 75
  • 1
  • 11
  • Possible duplicate of [LINQ to SQL - Left Outer Join with multiple join conditions](http://stackoverflow.com/questions/1122942/linq-to-sql-left-outer-join-with-multiple-join-conditions) –  Apr 11 '16 at 04:04

1 Answers1

0

Instead of Priority = x == null ? 1 : x.PRIORITY try Priority = p2 == null ? 1 : p2.PRIORITY

var Query = (from p in DestinationCustomerList
             join p2 in Context.SA_CUSTOMER_ALLOC 
                 on new 
                 { f1 = p.CustomerId, f2 = p.FieldId } 
                  equals new 
                 { f1 = p2.CUSTOMER_ID, f2 = p2.FIELD_ID }
                 into temp
              from x in temp.DefaultIfEmpty()
              let priority = p2 == null ? 1 : p2.PRIORITY
              where x.TAG_ID == TagId && x.REGION_ID == RegionId
              select new { p.CustomerId,p.FieldId, Priority = priority }).ToList();
Alex Art.
  • 8,711
  • 3
  • 29
  • 47