Visual Studio 2010、C#、および Entity Framework 5 を使用しています。LINQ クエリの結果である JSON 構造を生成しています。コントローラーには次のものがあります。
[HttpPost]
public ActionResult ICD10ConditionSearch(string ICD10SearchTerm)
{
CommonCodeEntities dataContextCommonCodes = new CommonCodeEntities(ConnectionString);
IQueryable<ICD10Codes> codes = dataContextCommonCodes.ICD10Codes.
Where(m => m.ICD10CodeTitle.Contains(ICD10SearchTerm));
return Json(codes);
}
これは正しく機能し、期待される結果を返します。
私が本当にやりたいことは、検索語の lst を使用して結果を連結することです。以下を使用する場合:
[HttpPost]
public ActionResult ICD10ConditionSearch(string ICD10SearchTerms)
{
String[] terms = ICD10SearchTerms.Split(' ');
IQueryable<ICD10Codes> codes = Enumerable.Empty<ICD10Codes>().AsQueryable();
IQueryable<ICD10Codes> codeLocal;
CommonCodeEntities dataContextCommonCodes = new CommonCodeEntities(ConnectionString);
foreach (var term in terms)
{
codeLocal = dataContextCommonCodes.ICD10Codes.Where(m => m.ICD10CodeTitle.Contains(term));
codes = codes.Concat(codeLocal);
}
return Json(codes);
}
これにより、次のエラーが生成されますThis method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
。Concat() の他のバリアントを試してみましたが、同じ結果が得られました。