实体中存在投放问题. [英] Having casting problem in Entity.
本文介绍了实体中存在投放问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var itemOne = 来自 n 其中 n.CodeNo ==代码
选择 n.CodeNo;
var itemTwo =来自 db中的来自 db.地址
其中(itemOne.Contains(p.AddCode))
选择 p;
运行时出现此错误-
LINQ to Entities无法识别方法``Boolean Contains [Decimal](System.Linq.IQueryable`1 [System.Decimal],System.Decimal)''方法,并且该方法无法转换为商店表达式. class ="h2_lin">解决方案
var itemOne
是Decimal
.您说,在查询itemOne
的末尾,它应该选择n.CodeNo
.因此,您选择的是Decimal
,而不是TimeTable
(我想您实际上要选择).
在itemTwo
查询中,您要查找itemOne
(一个TimeTableDecimal.Contains(AddCode)
.),一个Decimal
没有Contains Function
,所以它将永远找不到它!
var itemOne = 来自 n 在 db.TimeTable中 其中 n.CodeNo ==代码 选择 n; // 不是n.CodeNo! var itemTwo =来自 db中的来自 db.地址 其中(itemOne.Contains(p.AddCode)) 选择 p;
我认为这将解决您的问题.为了确保itemOne
和itemTwo
的类型悬停在其前面的var
关键字上.
希望对您有所帮助! :)
var itemOne = from n in db.TimeTable
where n.CodeNo == code
select n.CodeNo;
var itemTwo = from p in db.Address
where (itemOne.Contains(p.AddCode))
select p;
Got this error when run-
LINQ to Entities does not recognize the method ''Boolean Contains[Decimal](System.Linq.IQueryable`1[System.Decimal], System.Decimal)'' method, and this method cannot be translated into a store expression.
解决方案
var itemOne
is aDecimal
. You say, at the end of the query foritemOne
that it should selectn.CodeNo
. So you are selecting aDecimal
, not aTimeTable
(which I think you want to actually select).
In theitemTwo
query you want to look whereitemOne
(aTimeTableDecimal.Contains(AddCode)
. Well, aDecimal
does not have aContains Function
, so it will never find it!
var itemOne = from n in db.TimeTable where n.CodeNo == code select n; // Not the n.CodeNo! var itemTwo = from p in db.Address where (itemOne.Contains(p.AddCode)) select p;
I think that will solve your problem. To make sure what the type ofitemOne
anditemTwo
are hoover over thevar
keyword in front of it.
Hope that helps! :)
这篇关于实体中存在投放问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文