为什么我收到此错误 LINQ 表达式节点类型 'ArrayIndex' 在我的 linq 查询中不支持 LINQ to Entitie 错误?



我是entity frame work中的新手,并编写此查询:

var query_Books = (from p in Store1.CustomerBooks
                                   where p.CustomerID == query_User[i].id
                                   select new
                                   {
                                       p.BookName,
                                       p.BookCount
                                   }).ToArray();


但是获取此错误:

Additional information: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.


这是我的query_User查询:

var query_User = (from p in Store1.CustomerBuys
                              where p.NationalCode.Trim() == NationalCode 
                              select new
                              {
                                  p.id,
                                  p.NationalCode
                              }).ToArray();


我该如何解决这个问题?

linq无法将query_User[i]转换为expression。使用临时变量来工作,类似的东西:

var user = query_User[i];
var query_Books = (from p in Store1.CustomerBooks
                                   where p.CustomerID == user.id
                                   select new
                                   {
                                       p.BookName,
                                       p.BookCount
                                   }).ToArray();

将此query_User[i].id保存到温度变量。然后在查询中使用该温度变量。

最新更新