gpt4 book ai didi

asp.net-mvc - 为什么LINQ to Entities无法识别方法'System.String ToString()?

转载 作者:行者123 更新时间:2023-12-03 09:00:38 25 4
gpt4 key购买 nike

MVC3 Web应用程序内部出现错误。LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
当我尝试使用EF从查询中获取值时:

public class DataRepository
{
public mydataEntities1 dbContext = new mydataEntities1();

public List<SelectListItem> GetPricingSecurityID()
{
var pricingSecurityID = (from m in dbContext.Reporting_DailyNAV_Pricing
select new SelectListItem
{
Text = m.PricingSecurityID.ToString(),
Value = m.PricingSecurityID.ToString()
});

return pricingSecurityID.ToList();
}
}

最佳答案

那不能转换成SQL。我猜,从理论上讲,它可以,但是没有实现。

得到结果后,只需执行投影即可:

var pricingSecurityID = (from m in dbContext.Reporting_DailyNAV_Pricing
select m.PricingSecurityID).AsEnumerable()
.Select(x => new SelectListItem{ Text = x.ToString(), Value = x.ToString() });

关于asp.net-mvc - 为什么LINQ to Entities无法识别方法'System.String ToString()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10110266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com