简体   繁体   English

LINQ to Entities无法识别方法'Int32 ToInt32(System.String)'方法,并且此方法无法转换为存储表达式

[英]LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression

I get this error when I try this code : 我在尝试此代码时遇到此错误:

TaxiEntities db = new TaxiEntities();
bool IsUserPassCorrected = db.tblOperators.Any(item => item.UserName.ToLower() == txtUserName.Text.ToLower() &&
item.Password == Convert.ToInt32(txtPassWord.Text));

if (!IsUserPassCorrected)
{
    MessageBox.Show("Username or Password is incorrected! Please try again");
}

Since LINQ to Entities does not support Convert.ToInt32 , you need to parse to int outside LINQ first: 由于LINQ to Entities不支持Convert.ToInt32 ,因此需要先在LINQ之外解析为int

TaxiEntities db = new TaxiEntities();
int password = int.Parse(txtPassWord.Text);

bool IsUserPassCorrected = db.tblOperators
            .Any(item => item.UserName.ToLower() == txtUserName.Text.ToLower() 
                      && item.Password == password);

暂无
暂无

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

相关问题 LINQ to Entities无法识别方法'Int32 ToInt32(System.Object)'方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Object)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'Int32 ToInt32(System.String)'方法 - LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method LINQ to Entities 无法识别方法 'Int32 Int32(System.String)' 方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'System.String ToString(Int32)',并且该方法无法转换为商店表达式。“} - LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression."} LINQ to Entities无法识别方法'System.String ToString(Int32)'方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'System.String get_Item(Int32)',并且该方法无法转换为商店表达式 - LINQ to Entities does not recognize the method 'System.String get_Item(Int32)' method, and this method cannot be translated into a store expression LINQ to Entities 无法识别方法 'Int32 Parse(System.String)' 方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'Int32 ToInt32(System.Object)'方法 - LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Object)' method linq to entities无法识别int32 toint32的方法 - linq to entities does not recognize the method int32 toint32 LINQ to Entities无法识别方法'Int32 ToInt32(Boolean)' - LINQ to Entities does not recognize the method 'Int32 ToInt32(Boolean)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM