实体中存在投放问题. [英] Having casting problem in Entity.

查看:87
本文介绍了实体中存在投放问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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 itemOneDecimal.您说,在查询itemOne 的末尾,它应该选择n.CodeNo.因此,您选择的是Decimal,而不是TimeTable (我想您实际上要选择).
itemTwo 查询中,您要查找itemOne (一个 TimeTable Decimal.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 a Decimal. You say, at the end of the query for itemOne that it should select n.CodeNo. So you are selecting a Decimal, not a TimeTable (which I think you want to actually select).
In the itemTwo query you want to look where itemOne (a TimeTable Decimal.Contains(AddCode). Well, a Decimal does not have a Contains 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 of itemOne and itemTwo are hoover over the var keyword in front of it.
Hope that helps! :)


这篇关于实体中存在投放问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆