简体   繁体   English

LINQ 到实体 - LINQ 到实体无法识别方法“双重解析(System.String)”方法

[英]LINQ To Entity - LINQ to Entities does not recognize the method 'Double Parse(System.String)' method

Here is my c# codes:这是我的 c# 代码:

double amount_dbl = double.Parse("0.00001167");

using (Crypto_Shuffler_Entities entities = new Crypto_Shuffler_Entities())
{
    double amount_dbl = double.Parse("0.00001167");

    var order = (from Order in entities.Orders
                 where Order.BTC_Address == "123" && double.Parse(Order.BTC_Amount) == amount_dbl
                 select Order).FirstOrDefault();
    if (order != null)
    {
    }
}

BTC_Amount in sql server is string. BTC_Amount服务器中的 BTC_Amount 是字符串。
I really do n't know why i have such this error:我真的不知道为什么我会出现这样的错误:

LINQ to Entities does not recognize the method 'Double Parse(System.String)' method, and this method cannot be translated into a store expression. LINQ 到 Entities 无法识别方法 'Double Parse(System.String)' 方法,并且此方法无法转换为存储表达式。

Please give me a solution for both QUERY & METHOD ways of LINQ.请给我一个LINQ的QUERYMETHOD方式的解决方案。

Having a double value in SQL server as string is questionable.在 SQL 服务器中将双精度值作为字符串是有问题的。 Proably then you might also want to compare it as string without parsing at all.那么您可能还想将其作为字符串进行比较而不进行解析。 Assuming you would like you to do with parsing, double.Parse() doesn't have a corresponding conversion in EF you could indirectly do it at the client side:假设您希望您进行解析,double.Parse() 在 EF 中没有相应的转换,您可以在客户端间接进行:

var order = (from Order in entities.Orders
                 where Order.BTC_Address == "123"                  select Order)
           .AsEnumerable()
           .Where(o => double.Parse(o.BTC_Amount) == amount_dbl)
           .FirstOrDefault();

From the point forward you have AsEnumerable(), it is client side.从现在开始,您拥有 AsEnumerable(),它是客户端。

EDIT: And this is the method way:编辑:这是方法:

var order = entities.Orders
           .Where(Order => Order.BTC_Address == "123") 
           .AsEnumerable()
           .Where(o => double.Parse(o.BTC_Amount) == amount_dbl)
           .FirstOrDefault();

PS: I would directly write the double value instead of parsing from a string as in your example. PS:我会直接编写双精度值,而不是像您的示例中那样从字符串解析。

PS2: Also don't forget, with a double you are unlikely to get equal values. PS2:也不要忘记,使用 double 你不太可能得到相等的值。 In SQL server and C# side a decimal is a more appropriate type to use.在 SQL 服务器和 C# 端,十进制是更适合使用的类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LINQ to Entities 无法识别方法 'Double Parse(System.String)' 方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'Double Parse(System.String)' method, and this method cannot be translated into a store expression LINQ to Entities 无法识别“System.String Decrypt(System.String, System.String)”方法 - LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method LINQ to Entities无法识别方法'System.String ToString()'方法++++++ - LINQ to Entities does not recognize the method 'System.String ToString()' method ++++++ LINQ 实体无法识别方法'System.String ToShortDateString()'方法 - LINQ to Entities does not recognize the method 'System.String ToShortDateString()' method LINQ to Entities无法识别方法'System.String getFullname(System.String,System.String)' - LINQ to Entities does not recognize the method 'System.String getFullname(System.String, System.String)' LINQ to Entities无法识别方法'System.String StringConvert(System.Nullable`1 [System.Double]) - LINQ to Entities does not recognize the method 'System.String StringConvert(System.Nullable`1[System.Double]) LINQ to Entities无法识别方法'System.String [] ToArray [String] - LINQ to Entities does not recognize the method 'System.String[] ToArray[String] LINQ to Entities无法识别方法'System.Object Parse(System.Type,System.String)' - LINQ to Entities does not recognize the method 'System.Object Parse(System.Type, System.String)' LINQ to Entities无法识别方法'System.String - LINQ to Entities does not recognize the method 'System.String LINQ to Entities无法识别方法'System.String Format - LINQ to Entities does not recognize the method 'System.String Format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM