LINQ to SQL in and not in

前端 未结 3 1573
醉梦人生
醉梦人生 2020-11-29 09:44

What is in and not in equals in LINQ to SQL?

For example

select * from table in ( ...)
and 
select * from table not in (.         


        
3条回答
  •  醉梦人生
    2020-11-29 10:01

    Please Try This For SQL Not IN

    var v = from cs in context.Sal_Customer
             join sag in context.Sal_SalesAgreement
             on cs.CustomerCode equals sag.CustomerCode
             where
              !(
                   from cus in context.Sal_Customer
                   join
                   cfc in context.Sal_CollectionFromCustomers
                   on cus.CustomerCode equals cfc.CustomerCode
                   where cus.UnitCode == locationCode &&
                         cus.Status == Helper.Active &&
                         cfc.CollectionType == Helper.CollectionTypeDRF
                   select cus.CustomerCode
               ).Contains(cs.CustomerCode) &&
               cs.UnitCode == locationCode &&
               cs.Status == customerStatus &&
               SqlFunctions.DateDiff("Month", sag.AgreementDate, drfaDate) < 36
               select new CustomerDisasterRecoveryDetails
               {
                 CustomerCode = cs.CustomerCode,
                 CustomerName = cs.CustomerName,
                 AgreementDate = sag.AgreementDate,
                 AgreementDuration = SqlFunctions.DateDiff("Month", sag.AgreementDate, drfaDate)
       };
    

    Please Try This For SQL IN

    context.Sal_PackageOrItemCapacity.Where(c => c.ProjectCode == projectCode && c.Status == Helper.Active && c.CapacityFor.Contains(isForItemOrPackage)).ToList();
    

提交回复
热议问题