如何使用Linq实体从数据库中获取Dictionary?

时间:2014-11-15 15:40:54

标签: c# .net linq entity-framework

我使用类似的东西,但发生了一些例外。这是关于例外的信息。

例外: 类型' System.NotSupportedException'的例外情况发生在EntityFramework.SqlServer.dll中但未在用户代码中处理

其他信息:LINQ to Entities无法识别方法&#39; System.Collections.Generic.Dictionary 2[System.String,System.Collections.Generic.List 1 [System.Nullable 1[System.Int64]]] ToDictionary[<>f__AnonymousType5a 2,String,List 1](System.Collections.Generic.IEnumerable 1并[d&GT; f__AnonymousType5a 2[System.String,System.Collections.Generic.List 1 [System.Nullable 1[System.Int64]]]], System.Func 2 [&LT;&GT; f__AnonymousType5a 2[System.String,System.Collections.Generic.List 1 [System.Nullable 1[System.Int64]]],System.String], System.Func 2 [&LT;&GT; f__AnonymousType5a 2[System.String,System.Collections.Generic.List 1 [System.Nullable 1[System.Int64]]],System.Collections.Generic.List 1 [System.Nullable`1 [System.Int64]]])&#39;方法,并且此方法无法转换为商店表达式。

我的代码在这里:

            List<Match> matches = new List<Match>();
        using (var en = new LiveOddsEntities())
        {
            matches = (from m in en.Matches
                       join mi in en.MatchInfoes on m.match_id equals mi.match_id
                       join to in en.Tournaments on mi.tournament_id equals to.id
                       join ca in en.Categories on mi.category_id equals ca.id
                       join sp in en.Sports on mi.sport_id equals sp.id
                       join ht in en.Teams on mi.home_team_id equals ht.id
                       join at in en.Teams on mi.away_team_id equals at.id
                       where mi.DateOfMatch > ticks
                       orderby mi.DateOfMatch ascending
                       select new Match { MatchId = m.match_id, DateOfMatch = mi.DateOfMatch, Tournament = to.name, Category = ca.name, Sport = sp.name, HomeTeam = ht.name, AwayTeam = at.name, BetTypes = (from mat in en.Matches
                                                                                                                                                                                                             join odd in en.Odds on mat.match_id equals odd.match_id
                                                                                                                                                                                                             select new { odd.type, proba = (from matc in en.Matches
                                                                                                                                                                                                                                     join odds in en.Odds on matc.match_id equals odds.match_id
                                                                                                                                                                                                                                     where odd.type ==odds.type
                                                                                                                                                                                                                                     select odds.subtype).ToList()}
                                                                                                                                                                                                                ).AsEnumerable().ToDictionary(k => k.type, k => k.proba) }).Skip(skip).Take(pageSize).ToList();
        }
        return matches;

0 个答案:

没有答案