LINQ和ToString()方法的问题 [英] Problems with LINQ and ToString() method

查看:75
本文介绍了LINQ和ToString()方法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LINQ to Entities无法识别方法"System.String ToString()",并且该方法无法转换为商店表达式


我正在使用以下代码:

LINQ to Entities does not recognize the method ''System.String ToString()'' method, and this method cannot be translated into a store expression


I''m using the following code :

using(var sd=new dataEntities())
{
var listofdata=sd.users.where(d=>d.id.ToString().Contain("2"));// id as int
// error : LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
}

推荐答案

answer:var listofdata = sd.users.where(d => SqlFunctions.StringConvert((double?)d.id). Contain("2"));
answer : var listofdata=sd.users.where(d=>SqlFunctions.StringConvert((double?)d.id).Contain("2"));


这篇关于LINQ和ToString()方法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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