Code :
var page = (from p in dbContext.Page
where p.Id== Id
select new PageObject
{
PageID = p.PageID,
CategoryId = p.attr.Any(a => a.Attribute == "CategoryId") ?
p.attr.Where(a => a.Attribute == "CategoryId").FirstOrDefault().Value : 0 // How do I convert the Value to Int?
}).FirstOrDefault();
Problem :
We are using EF in existing application where in the above code it is initializing PageObject (with lots of properties which I have deleted for simplicity).The CategoryId is an integer and I am trying to figure out how to convert the Value to int, I am unable to use int.Parse on the LINQ query as it throws an error :
LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression.
Note: I cannot avoid using short hand property initialization, and this needs to be done in the LINQ query itself.