Linq到实体错误 [英] Linq to Entitities Error
本文介绍了Linq到实体错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我正在尝试从称为使用Linq到Entities的实践的表中获取一些值.
练习表包含以下内容.
PracticeID自动增量,
PracticeName nvarchar(10),
等
现在我需要从此列表中获得3种做法.
Hello,
I am trying to fetch some values from a table called practices using Linq to Entities.
Practices table contains the following.
PracticeID AutoIncrement,
PracticeName nvarchar(10),
etc.
now i need to get 3 practices from this list.
stirng [] pras = new string [] {"1", "3", "5"}
AuthenticationEntities authEntity = new AuthenticationEntities();
List<practices> prac = (from p in authEntity.Practices
where pras.Contains(p.PracticeID.ToString())
select new Practices
{
Practice = p.PracticeName
}).ToList<practices>();
但这显示为错误
LINQ to Entities无法识别方法"System.String ToString()",因此该方法无法转换为商店表达式.
But it is showing as error
LINQ to Entities does not recognize the method ''System.String ToString()'' method, and this method cannot be translated into a store expression.
Kindly help.
推荐答案
为什么不将数组声明为int类型(或将该字段定义为任何数字类型)?
Why not declare the array as int type (or whatever numeric type the field is defined as)?
int [] pras = new int[] {1, 3, 5};
var authEntity = new AuthenticationEntities();
var prac = (from p in authEntity.Practices
where pras.Contains(p.PracticeID)
select new Practices
{
Practice = p.PracticeName
})
.ToList<Practices>();
请参阅以下示例.
http://msdn.microsoft.com/en-us/vstudio/bb737939#strcont [ ^ ]
您可以使用contains找到文本.
在这里,您的PracticeID为Integer,并且将其与字符串进行比较,因此存在转换问题. 我认为你不能做这样的演员
我建议为此使用存储过程.
谢谢,
Viprat Shah
see the below example.
http://msdn.microsoft.com/en-us/vstudio/bb737939#strcont[^]
you can find the text using contains.
here your PracticeID is Integer and you are comparing it with string so there is casting problem.
i think you can`t do casting like this
i suggest use stored procedure for this.
Thanks,
Viprat Shah
请看看@ 此讨论 [ ^ ]
谢谢
-Amit Gajjar
Hi,
Please have a look @ this Discussion[^]
Thanks
-Amit Gajjar
这篇关于Linq到实体错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文