您好我有FEATURESET標識的數組,我的車表得到了子表作爲FeatureSets 我寫的SQL查詢像LinqToSql子Entiity多和運營商
SELECT [t0].[ID]
FROM [dbo].[SearchResultView] AS [t0]
Join [dbo].[VehicleFeatureSet] AS [t1] on t0.ID = t1.VehicleID
where t1.FeatureSetID = 1 and t1.FeatureSetID= 2 and t1.FeatureSetID= 3
我試過了。但我不能
var features = Request.QueryString["FeatureSets"].Split(',').ToList().ConvertAll(new Converter<string, int>(StrinToint));
IQueryable<SearchResultView> result = db.SearchResultViews.Where(m => m.Active == true);
foreach (var featuree in features)
{
result = result.Where(m => m.VehicleFeatureSets.Any(c => c.FeatureSetID == featuree));
}
我怎麼可以這樣寫LINQ查詢
正如Mattytommo指出的那樣,您的SQL查詢包含一個始終爲false的謂詞('t1.FeatureSetID = 1和...')。有趣的是,我認爲你的linq完全符合你想要達到的目標,但是生成的SQL當然是不同的。我認爲它包含'EXISTS's,但它應該包含它們。這是假設你想要'SearchResultView'記錄在他們的'VehicleFeatureSet'中有_both_1和_2 _and_3。 – 2012-03-30 19:49:34