我将一个字符串传递给控制器,并且需要控制器在我的数据库的Title字段内搜索传递的任何单词。在Linq查询中搜索任何词
例如。 ID =“前景错误消息”
[HttpPost]
public JsonResult Lookup(string id)
{
List<string> listOfSearch = id.Split(' ').ToList();
var results = db.KS.Where(x => x.Title.Intersect(listOfSearch).Any());
这将产生以下两个错误:
实例论证:不能从“字符串”转换为“
System.Linq.IQueryable<string>
‘字符串’中不包含'Intersect'的定义和最佳延伸方法过载'
System.Linq.Queryable.Intersect<TSource>(System.Linq.IQueryable<TSource>, System.Collections.Generic.IEnumerable<TSource>)
'有一些无效参数
Ca任何人都请告知有什么不对,或者如何用包含任何传入单词的标题列表填充结果?
谢谢,马克
我有A S不久前的类似问题:http://stackoverflow.com/questions/16215100/linq-to-entities-orderby-statement-involving-extension-method(它对您遇到的问题有一个答案) – HennyH 2013-04-30 10:58:43