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'
我缺少什麼?