0
点赞
收藏
分享

微信扫一扫

mvc ef LINQ to Entities 不识别方法 “Int32 Parse (System.String)”,因此该方法无法转换为存储表达式。

mvc ef LINQ to Entities 不识别方法 “Int32 Parse (System.String)”,因此该方法无法转换为存储表达式。_System

private sys_User GetUserInfo()
{
sys_User model = null;
var userId = Convert.ToInt32(AccountHelper.GetAccountUserId());
var list = BLLSingleton.Instance.IUserService.GetListBy(c => c.UserId == userId);
if (list != null)
model = list.FirstOrDefault();
return model;
}

 

---------------------------------------------------------------------------------------

mvc ef  识别不了的 (会报 LINQ to Entities 不识别方法 “Int32 ToInt32 (System.String) 错误)

原因在于 linq 表达式中无法识别 convert 方法.

因为 where 里面不能调用这种 convert 等 C# 方法 要么在外面转好了 int 类型添加进去

tostring 等方法也不能放到 where 里面调用 因为他要解析 lamda 表达式 而不是去解析 C# 的方法

所以事前将 string 转成 int 在用

var userId = Convert.ToInt32(AccountHelper.GetAccountUserId());

举报

相关推荐

0 条评论