LINQ

时间:2016-04-11 03:59:43

标签: linq

基本上我想用SA_CUSTOMER_ALLOC检查DestinationCustomerList,如果根据customerId和fieldId找到任何记录然后返回优先级,则优先级= 1,所以我使用左外连接实体但它没有正常工作(只返回匹配记录,如果SA_CUSTOMER_ALLOC没有任何记录投掷"对象参考错误"如何处理。

  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();

0 个答案:

没有答案