LINQ to Entities不识别方法';Int32到Int32(System.String)';方法,

本文关键字:Int32 方法 System String LINQ Entities to 识别 | 更新日期: 2023-09-27 18:20:37

当我尝试以下代码时,会出现此错误:

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");
}

LINQ to Entities不识别方法';Int32到Int32(System.String)';方法,

由于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);
相关文章: