I have code
foreach (XElement t in selxml.Elements("Type"))
printxml.Add(new XElement("Type",
new XAttribute("TypeID", t.Attribute("ID").Value),
new XAttribute("TypeName", (from pt in fdb.PrintTypes where pt.PrintTypeID == Int32.Parse(t.Attribute("ID").Value) select pt.Name).SingleOrDefault()),
new XAttribute("Value", t.Attribute("Value").Value),
new XAttribute("ValueName", (from pti in fdb.PrintTypeItems
where pti.Value == Int32.Parse(t.Attribute("Value").Value) &&
pti.PrintTypeID == Int32.Parse(t.Attribute("ID").Value)
select pti.Name).SingleOrDefault())));
and VS say
LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression.
why LINQ to Entities? this is Linq to XML. How can I solve this problem?
I recommend that you use the Int32.Parse method before you call the Add method, within the foreach loop. You can save the two as local variables (Value and ID) and use them in your same query.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.