在我的项目中,我使用Entity Framework和MySQL。 这段代码:
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()
工作正常。
有人遇到过这个问题吗?
答案 0 :(得分:3)
是。完全相同的问题。我确认take
存在join
似乎是个问题。在我的情况下,因为我将EF查询投影到一个对象上,直接在数据库上执行take
而不是在投影后本地执行(objectContext.users.Include("posts").ToList()
的等效项),这会产生巨大的差异。消耗的时间和消耗的内存。