文章内容
2017/7/28 10:10:22,作 者: 黄兵
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.
今天在写代码的时候报如下错误:
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.
截图如下:
应该是Linq表达式不支持采用数组索引查询实体。
看一下代码:
using(UnitOfWork uow=new UnitOfWork()) { int pre = 0, next = 0, i = 0, j; var BlogItem = uow.BlogRepository.GetAll().Where(x => x.Id > 866); var getIdList=BlogItem.Select(x => x.Id); int num = BlogItem.Count(); int[] a = new int[num]; Console.WriteLine("开始建立索引!"); foreach(var item in getIdList) { a[i] = Convert.ToInt32(item); i++; Console.WriteLine("正在为Id为{0}的文章建立索引……", item); var getItem = uow.BlogRepository.Get(x => x.Id == a[i]); SearchIndexManager.GetInstance().AddQueue(getItem.Id.ToString(), getItem.Title, getItem.Body, getItem.CreationTime); } Console.WriteLine("建立索引完成。"); }
解决方案:
Console.WriteLine("正在为Id为{0}的文章建立索引……", item); var getItem = uow.BlogRepository.Get(x => x.Id == item); SearchIndexManager.GetInstance().AddQueue(getItem.Id.ToString(), getItem.Title, getItem.Body, getItem.CreationTime);
黄兵的个人博客原创。
转载请注明出处:黄兵的个人博客 - The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.
评论列表