简体   繁体   English

LINQ to Entities无法识别方法'System.Collections.Generic.Dictionary`

[英]LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary`

I have this erun time error exception 我有这个错误的时间错误异常

LINQ to Entities does not recognize the method
 'System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[Project.Model.Value]]
ToDictionary[Value,String,List`1](System.Collections.Generic.IEnumerable`1[Project.Model.Value],
System.Func`2[Project.Model.Value,System.String],
System.Func`2[Project.Model.Value,System.Collections.Generic.List`1[Project.Model.Value]])'
method, and this method cannot be translated into a store expression.

I tried what ever I can to fixed it but no use. 我尽力修复它但没用。 I think the exception coming from list can someone help me to fix it 我认为来自列表的异常可以帮助我解决它

public IEnumerable<ItemManagement> getItemsForFormType(string formType)
        {
            using (var db = new AthenaContext())
            {

                List<Value> dropDownListValue = (from val in db.Values
                                                 where val.ParentId == (from va in db.Values
                                                                        where
                                                                            va.ParentId
                                                                            == (from value3 in db.Values
                                                                                where value3.Name == formType
                                                                            select value3.RecordId).FirstOrDefault()
                                                                    select va.RecordId).FirstOrDefault()
                                             select val).ToList();
            var result = (from value1 in db.Values
                          where value1.Name == formType
                          select
                              new ItemManagement
                              {

                                  FormType = value1.Name,
                                  RecordID = value1.RecordId,
                                  FormControllerNames =
                                  (from va in db.Values
                                   where va.ParentId == (from value3 in db.Values where value3.Name == formType select value3.RecordId).FirstOrDefault()
                                   select va).ToDictionary(va => va.Name, va => dropDownListValue)
                              }).ToList();
            return result;
        }

You are trying to embed a .NET library function to your EF query. 您正在尝试将.NET库函数嵌入到EF查询中。 As it is not translatable to SQL, this is not supported. 因为它不能翻译成SQL,所以不支持。

You must rewrite your query, without using the .ToDictionary(). 您必须重写查询,而不使用.ToDictionary()。

This particular case it may not to hard. 这种特殊情况可能并不难。 Please revisit if the projection ToDictionary() is necessary at all. 如果根本需要投影ToDictionary(),请重新访问。 You can safely write SQL translatable projection by using: 您可以使用以下方法安全地编写SQL可翻译投影:

.Select( new { anyName: <expression>, otherName: <otherExpression>, etc })

暂无
暂无

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

相关问题 LINQ to Entities 无法识别方法“System.Collections.Generic.Dictionary”2[System.Int32,System.String] ToDictionary - LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary`2[System.Int32,System.String] ToDictionary LINQ to Entities无法识别方法&#39;System.Collections.Generic.IEnumerable`1 - LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1 DefaultIfEmpty()引起“ System.NotSupportedException:LINQ to Entities无法识别方法&#39;System.Collections.Generic.IEnumerable&#39;” - DefaultIfEmpty() Causing “System.NotSupportedException: LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable'” &#39;System.Collections.Generic.Dictionary的最佳重载方法匹配 <int,System.Collections.Generic.Dictionary<string,int> &gt; .Dictionary(int)&#39; - The best overloaded method match for 'System.Collections.Generic.Dictionary<int,System.Collections.Generic.Dictionary<string,int>>.Dictionary(int)' System.Collections.Generic.Dictionary =终极表现? - System.Collections.Generic.Dictionary = Ultimate performance? System.Collections.Generic.Dictionary foreach顺序 - System.Collections.Generic.Dictionary foreach order 将System.Collections.Generic.Dictionary转换为XDocument - Turn a System.Collections.Generic.Dictionary into an XDocument 反序列化 System.Collections.Generic.Dictionary - deserializing System.Collections.Generic.Dictionary System.MissingMethodException:找不到方法&#39;System.Collections.Generic.Dictionary`2.GetValueOrDefault&#39; - System.MissingMethodException: Method 'System.Collections.Generic.Dictionary`2.GetValueOrDefault' not found 为什么并行访问和改变 System.Collections.Generic.Dictionary 不会导致异常/崩溃? - Why does accessing and mutating a System.Collections.Generic.Dictionary in parallel not result in exceptions/crashes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM