简体   繁体   English

LINQ to Entities无法识别方法'System.Object Parse(System.Type,System.String)'

[英]LINQ to Entities does not recognize the method 'System.Object Parse(System.Type, System.String)'

I am getting this error, i am trying to resolve it long but unable to fix it. 我收到此错误,我试图解决它很长但无法解决它。 LINQ to Entities does not recognize the method 'System.Object Parse(System.Type, System.String)' method, and this method cannot be translated into a store expression. LINQ to Entities无法识别方法'System.Object Parse(System.Type,System.String)'方法,并且此方法无法转换为商店表达式。

 public static List<itmCustomization> GetAllProductCustomziation(string catID)
            {
                var arrcatID = catID.Split('_');
                int PId = int.Parse(arrcatID[0].ToString());
                int CatID = int.Parse(arrcatID[1].ToString());
                EposWebOrderEntities db = new EposWebOrderEntities();
                List<itmCustomization> lstCust = new List<itmCustomization>();
                lstCust.AddRange((from xx in db.vw_AllCustomization
                                  where xx.CatID == CatID && xx.ProductID == PID
                                  select new itmCustomization()
                                  {
                                      itmName = xx.Description,
                                      catId = (int)xx.CatID,
                                      proId = (int)xx.ProductID,
                                      custType = (customizationType)Enum.Parse(typeof(customizationType), xx.CustType)
                                  }).ToList<itmCustomization>());
                return lstCust;

            }

As you're using LINQ To Entities, Entity Framework is currently trying to translate Enum.Parse into SQL, and it fails, because it's not a supported function. 当您使用LINQ To Entities时,Entity Framework目前正在尝试将Enum.Parse转换为SQL,但它失败了,因为它不是受支持的函数。

What you could do is materialize your SQL request before calling Enum.Parse : 你可以做的是在调用Enum.Parse之前实现你的SQL请求:

lstCust.AddRange((from xx in db.vw_AllCustomization
                                  where xx.CatID == CatID && xx.ProductID == PID
                                  select xx)
                        .TolList()  // Moves to LINQ To Object here
                        .Select(xx => new itmCustomization()
                                  {
                                      itmName = xx.Description,
                                      catId = (int)xx.CatID,
                                      proId = (int)xx.ProductID,
                                      custType = (customizationType)Enum.Parse(typeof(customizationType), xx.CustType)
                                  }).ToList<itmCustomization>());

I think this error is being throw for custType = (customizationType)Enum.Parse(typeof(customizationType), xx.CustType) . 我认为这个错误正在抛出custType = (customizationType)Enum.Parse(typeof(customizationType), xx.CustType) BTW what is the type of xx.CustType? BTW是什么类型的xx.CustType? I thing it is returning string but the expected type is an enum thats why it is throwing this error. 我认为它返回字符串,但预期的类型是枚举,这就是为什么它抛出这个错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LINQ to Entities 无法识别“System.Object get_Item(System.String)”方法 - LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method LINQ to Entities无法识别方法&#39;System.String Concat(System.Object)&#39;方法, - LINQ to Entities does not recognize the method 'System.String Concat(System.Object)' method, LINQ to Entities无法识别方法&#39;System.Object get_Item(System.String)&#39; - LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' 错误:LINQ to Entities无法识别字符串转换时发生的方法&#39;System.String ToString(System.Object)&#39;方法 - Error: LINQ to Entities does not recognize the method 'System.String ToString(System.Object)' method occurs while string conversion LINQ to Entities无法识别方法&#39;System.String ToString(System.Object)&#39;方法错误,且字段可为空 - LINQ to Entities does not recognize the method 'System.String ToString(System.Object)' method error occurs with nullable fields LINQ to Entities 无法识别方法“System.Object get_Item(System.String)”方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method cannot be translated into a store expression 执行查询:“ LINQ to Entitites无法识别方法&#39;System.Object getItem(System.String)&#39;” - Excuting query: “LINQ to Entitites does not recognize method 'System.Object getItem(System.String)'” LINQ to Entities 无法识别“System.String Decrypt(System.String, System.String)”方法 - LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method LINQ to Entities无法识别方法&#39;System.String getFullname(System.String,System.String)&#39; - LINQ to Entities does not recognize the method 'System.String getFullname(System.String, System.String)' LINQ to Entities 无法识别方法“System.Object GetValue(…)” - LINQ to Entities does not recognize the method 'System.Object GetValue(…)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM