3
我无法将以下SQL查询转换为C#中的lambda表达式。我尝试加入但它给我错误。LINQ检查值不在自定义对象的多个列表中
SQL查询:
SELECT DISTINCT Customer.* FROM Customer INNER JOIN RouteCustomer ON Customer.CustomerId = RouteCustomer.CustomerId
WHERE
RouteCustomer.RouteId = @RouteId AND
Customer.Inactive = 0 AND
AND
(
(Customer.CustomerId NOT IN (SELECT CustomerId FROM RouteStopScheduleRule WHERE @Date >= EffectiveDate AND Inactive = 0))
OR
(
(Customer.CustomerId IN (SELECT CustomerId FROM RouteStopScheduleRule WHERE @Date >= EffectiveDate AND Inactive = 0 AND WeeklyFrequency = 0))
AND
(Customer.CustomerId NOT IN (SELECT CustomerId FROM RouteStopScheduleRule WHERE @Date >= EffectiveDate AND Inactive = 0 AND WeeklyFrequency != 0))
)
)
代码,我在C#中试过是
IEnumerable<RouteStopScheduleRule> RSRList1 = App.Database.AllRouteStopScheduleRule.Where(rsr1 => rsr1.EffectiveDate >= Date && rsr1.Inactive == false).AsEnumerable();
IEnumerable<RouteStopScheduleRule> RSRList2 = App.Database.AllRouteStopScheduleRule.Where(rsr2 => rsr2.EffectiveDate >= Date && rsr2.Inactive == false && rsr2.WeeklyFrequency == 0).AsEnumerable();
IEnumerable<RouteStopScheduleRule> RSRList3 = App.Database.AllRouteStopScheduleRule.Where(rsr3 => rsr3.EffectiveDate >= Date && rsr3.Inactive == false && rsr3.WeeklyFrequency != 0).AsEnumerable();
List<Customer> _Result = new List<Customer>();
var _Prelist = App.Database.AllCustomer.Where(c1 => c1.Inactive == false)
.Join(App.Database.AllRouteCustomer.Where(rc1 => rc1.RouteId == RouteId && (rc1.EffectiveDate <= Date && (rc1.ExpiryDate <= Date || rc1.ExpiryDate.Value.AddYears(1) <= Date))),
rc => rc.CustomerId,
c => c.CustomerId,
(rc, c) => new { CustomerId = c.CustomerId })
.Where(x => (!RSRList1.Contains(x.CustomerId)) || (RSRList2.Contains(x.CustomerId) && (!RSRList3.Contains(x.CustomerId))));
,但在所有的列表RSRList1它给我的错误,RSRList2和RSRList3为IEnumerable <>多年平均值包含定义'Contains'
我缺少什么?