I have to convert a string
value to int
, but it seems LINQ to Entities does not support this.
For the following code, I am getting an error.
var query = (from p in dc.CustomerBranch
where p.ID == Convert.ToInt32(id) // here is the error.
select new Location()
{
Name = p.BranchName,
Address = p.Address,
Postcode = p.Postcode,
City = p.City,
Telephone = p.Telephone
}).First();
return query;
LINQ to Entities does not recognize the method '
Int32 ToInt32 (System.String)
', and this method can not be translated into a store expression.
Do the conversion outside LINQ:
var idInt = Convert.ToInt32(id);
var query = (from p in dc.CustomerBranch
where p.ID == idInt
select new Location()
{
Name = p.BranchName,
Address = p.Address,
Postcode = p.Postcode,
City = p.City,
Telephone = p.Telephone
}).First();
return query;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With