报错信息 :LINQ to Entities does not recognize the method ‘Int32 Parse(System.String)’ method, and this method
var data = from v in db.Vip
join b in db.Business on v.BusinessId equals b.Id
where v.Level == int.Parse(level) // 这样写会报错
select new VipInfoModel
{
VipName = v.VipName,
Level = v.Level.Value,
BusinessId = v.BusinessId.Value,
BusinessName = b.Name,
DisplayName = b.DisplayName
};
解决方案:把int.parse拿到外面
var _level = int.Parse(level);
var data = from v in db.Vip
join b in db.Business on v.BusinessId equals b.Id
where v.Level == _level
select new VipInfoModel
{
VipName = v.VipName,
Level = v.Level.Value,
BusinessId = v.BusinessId.Value,
BusinessName = b.Name,
DisplayName = b.DisplayName
};
本文为“技术点滴”的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。