简体   繁体   English

LINQ to Entities无法识别方法'Int32 Parse(System.String)'为什么?

[英]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.

相关问题 LINQ to Entities无法识别方法'Int32 Parse(System.String)'方法, - LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, LINQ to Entities 在尝试解析不等式比较的列时无法识别方法“Int32 Parse(System.String)” - LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method when attempting to parse a column for inequality comparisons LINQ to Entities无法识别方法'Int32 ToInt32(System.String)'方法 - LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method LINQ to Entities 无法识别方法 'Int32 Parse(System.String)' 方法,并且此方法无法转换为存储表达式 - 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 IndexOf(System.String,System.StringComparison)'方法 - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method LINQ to Entities 无法识别方法 'Int32 Int32(System.String)' 方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'System.String GetMonthName(Int32)'方法 - LINQ to Entities does not recognize the method 'System.String GetMonthName(Int32)' method LINQ to Entities无法识别方法'Int32 CompareTo(System.String)'方法 - LINQ to Entities does not recognize the method 'Int32 CompareTo(System.String)' method LINQ to Entities 无法识别“System.String get_Item(Int32)”方法 - LINQ to Entities does not recognize the method 'System.String get_Item(Int32)' method LINQ to Entities无法识别方法'System.String ToString(Int32)'方法 - LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM