LINQ to Entities无法识别方法'Double Parse(System.String)'无法转换为商店表达式C#asp.net [英] LINQ to Entities does not recognize the method 'Double Parse(System.String)' cannot be translated into a store expression C# asp.net
本文介绍了LINQ to Entities无法识别方法'Double Parse(System.String)'无法转换为商店表达式C#asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试按部门顺序订购部门,但是由于部门号以字符串形式存储在数据库中,所以我不能仅使用按部门订购. 我尝试将其解析为float,但没有用.然后,我尝试将其解析为Double.那也不行.有什么建议?以下是我的代码.
I try to order Departments by number, but since the departement number stored as a string in database, I can't just use Order by number. I try to parse it as float but it did not work. Then I tried to parse it as Double. That does not work either. Any suggestions? The following is my code.
using (var db = new Context())
{
var datasource = (from x in db.Departments
orderby double.Parse(x.DepartmentNumber)
select x).ToList();
lvData.DataSource = datasource;
lvData.DataBind();
}
感谢您的回答,我做了以下工作,但结果并不完全正确.
Thanks for the answer, I did the following, but the results are not entirly correct.
var datasource = (from x in db.Departments orderby x.DepartmentNumber select x).ToList().OrderBy(Department => float.Parse(Department.DepartmentNumber));
推荐答案
实际上,以下内容解决了该问题并提供了所需的结果:
Actually the following solved the problem and provided the required results:
var datasource = (from x in db.Departments orderby x.DepartmentNumber select x).ToList().OrderBy(Department => Convert.ToDouble(Department.DepartmentNumber, System.Globalization.CultureInfo.InvariantCulture));
这篇关于LINQ to Entities无法识别方法'Double Parse(System.String)'无法转换为商店表达式C#asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文