Linq到实体错误

编程入门 行业动态 更新时间:2024-10-25 00:32:30
本文介绍了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>();

请参阅以下示例. msdn.microsoft/en-us/vstudio/bb737939#strcont [ ^ ] 您可以使用contains找到文本. 在这里,您的PracticeID为Integer,并且将其与字符串进行比较,因此存在转换问题. 我认为你不能做这样的演员 我建议为此使用存储过程. 谢谢, Viprat Shah see the below example. msdn.microsoft/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到实体错误

本文发布于:2023-06-03 10:04:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/473739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   错误   Linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!