をスローどこの内側に私は非サポート例外を取得: ローカルシーケンスは除きクエリ演算子のSQL実装にLINQで使用することはできません Contains()演算子。LINQの交差(...)いずれか()句は非サポート例外
[WebMethod]
public static object GetAnswersForSurvey(string surveyName, int? surveyYear, IEnumerable<string> tags, IEnumerable<string> benchmarks)
{
IQueryable<DAL.Answer> results = new DataClassesDataContext().Answers
.OrderBy(a => a.Question.Variable);
if (!String.IsNullOrEmpty(surveyName)) results = results.Where(a => a.Survey.Name == surveyName);
if (surveyYear.HasValue) results = results.Where(a => a.Survey.Year == surveyYear.Value);
if (tags.Any()) results = results.Where(answer => answer.Question.Tags.Select(t => t.Label).Intersect(tags).Any());
if (benchmarks.Any()) results = results.Where(answer => benchmarks.Contains(answer.Question.BenchmarkCode));
return results.Select(a => new {
a.Question.Wording,
a.Demographic,
Benchmark = a.Question.BenchmarkCode,
a.Question.Scale,
a.Mean,
a.MEPMean,
a.NSSEMean
});
}
私が試している方法ではできない場合があります。それが不可能な場合は、誰にでも代替案を提示できますか?
if(tags.Any())results = results.AsEnumerable()。ここで(answer => answer.Question.Tags.Select(t => t.Label).Intersect(tags).Any())。 AsQueryable(); それは機能します...しかし、私はすべて汚いと感じます。 –