LINQ to Entities does not recognize the method 'Int32 Pa

本文关键字:Int32 Pa method the Entities to does not recognize LINQ | 更新日期: 2023-09-27 18:15:48

我有代码

 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())));

和VS说

LINQ到实体不能识别Int32方法解析(System.String)'方法,此方法无法翻译

为什么LINQ到实体?这就是Linq to XML。我该如何解决这个问题?

LINQ to Entities does not recognize the method 'Int32 Pa

我建议您使用Int32。在foreach循环中,在调用Add方法之前解析方法。您可以将这两个保存为本地变量(Value和ID),并在相同的查询中使用它们。

相关文章: