Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
}
like image 391
m0n5t3r Avatar asked Jul 01 '13 11:07

m0n5t3r


1 Answers

Since LINQ to Entities does not support Convert.ToInt32, you need to parse to int outside LINQ first:

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);
like image 85
cuongle Avatar answered Nov 14 '22 22:11

cuongle