2012-02-29 2 views
0

В моем проекте я использую Entity Framework с MySQL. этот код:Entity Framwork: Значение не может быть нулевым. Имя параметра: key

objectContext.users.Include("posts").Take(2).ToList() 

бросает исключение: System.ArgumentNullException: Value cannot be null. Parameter name: key

с такой трассировки стека:

[ArgumentNullException: Value cannot be null. 
Parameter name: key] 
    System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +12670485 
    MySql.Data.Entity.Scope.GetFragment(String name) +27 
    MySql.Data.Entity.SelectStatement.AddDefaultColumns(Scope scope) +177 
    MySql.Data.Entity.SelectStatement.Wrap(Scope scope) +90 
    MySql.Data.Entity.SelectGenerator.WrapJoinInputIfNecessary(InputFragment fragment, Boolean isRightPart) +251 
    MySql.Data.Entity.SelectGenerator.HandleJoinExpression(DbExpressionBinding left, DbExpressionBinding right, DbExpressionKind joinType, DbExpression joinCondition) +110 
    MySql.Data.Entity.SelectGenerator.Visit(DbJoinExpression expression) +33 
    MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) +50 
    MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type) +19 
    MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression) +45 
    MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) +50 
    MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type) +19 
    MySql.Data.Entity.SelectGenerator.Visit(DbSortExpression expression) +61 
    MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) +50 
    MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type) +19 
    MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression) +45 
    MySql.Data.Entity.SelectGenerator.GenerateSQL(DbCommandTree tree) +73 
    MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) +401 
    System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) +608 

Интересно, что objectContext.users.Take(2).ToList() или objectContext.users.Include("posts").ToList() работает отлично.

Кто-нибудь столкнулся с этой проблемой?

ответ

3

Да. Точно такая же проблема. Я подтверждаю, что проблема take в присутствии join. В моем случае, поскольку я проектирую EF-запрос на объект, делая take непосредственно на БД, а не локально после проекции (эквивалент вашего objectContext.users.Include("posts").ToList(), имеет огромное значение с точки зрения времени и памяти.

Смежные вопросы