[英]LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' why?
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 和VS说
LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression.
LINQ to Entities无法识别方法'Int32 Parse(System.String)'方法,并且该方法无法转换为商店表达式。
why LINQ to Entities? 为什么要使用LINQ to Entities? this is Linq to XML.
这是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. 我建议您在foreach循环中调用Add方法之前,先使用Int32.Parse方法。 You can save the two as local variables (Value and ID) and use them in your same query.
您可以将它们另存为局部变量(值和ID),并在同一查询中使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.