【发布时间】:2016-07-07 21:48:42
【问题描述】:
请我使用此代码从 sql server 数据库中获取实体
MyDbContext dbct = new MyDbContext (); IQueryable 查询 = dbct.MyEntity;
但是每次我尝试获取我的查询时,我都会遇到这些异常
System.ArgumentNullException:值不能为空。
参数名称:构造函数
在 System.Linq.Expressions.Expression.New(ConstructorInfo 构造函数,IEnumerable1 arguments)
at Microsoft.Data.Entity.Metadata.Internal.EntityMaterializerSource.CreateMaterializeExpression(IEntityType entityType, Expression valueBufferExpression, Int32[] indexMap)
at Microsoft.Data.Entity.Query.ExpressionVisitors.Internal.MaterializerFactory.CreateMaterializer(IEntityType entityType, SelectExpression selectExpression, Func3 projectionAdder,IQuerySource querySource)
在 Microsoft.Data.Entity.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitEntityQueryable(类型 elementType)
在 Microsoft.Data.Entity.Query.ExpressionVisitors.EntityQueryableExpressionVisitor.VisitConstant(ConstantExpression constantExpression)
在 System.Linq.Expressions.ConstantExpression.Accept(ExpressionVisitor 访问者)
在 Microsoft.Data.Entity.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(表达式表达式)
在 Microsoft.Data.Entity.Query.EntityQueryModelVisitor.ReplaceClauseReferences(表达式表达式,IQuerySource 查询源,布尔 inProjection)
在 Microsoft.Data.Entity.Query.EntityQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause,QueryModel queryModel)
在 Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause,QueryModel queryModel)
在 Microsoft.Data.Entity.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause,QueryModel queryModel)
在 Remotion.Linq.Clauses.MainFromClause.Accept(IQueryModelVisitor 访问者,QueryModel queryModel)
在 Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
在 Microsoft.Data.Entity.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
在 Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
在 Microsoft.Data.Entity.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
在 Microsoft.Data.Entity.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
在 Microsoft.Data.Entity.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
--- 从先前抛出异常的位置结束堆栈跟踪 ---
在 Microsoft.Data.Entity.Query.Internal.QueryCompiler.c__DisplayClass18_01.<CompileQuery>b__0()
at Microsoft.Data.Entity.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 编译器)
在 Microsoft.Data.Entity.Query.Internal.QueryCompiler.CompileQuery[TResult](表达式查询)
在 Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](表达式查询)
在 Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](表达式表达式)
在 Remotion.Linq.QueryableBase1.GetEnumerator()
at Microsoft.Data.Entity.Internal.InternalDbSet1.System.Collections.Generic.IEnumerable.GetEnumerator()
在 System.Collections.Generic.List1..ctor(IEnumerable1 集合)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 源)
【问题讨论】:
-
您的问题中确实没有太多信息,但乍一看您的实体类型似乎没有无参数构造函数。
-
非常感谢我忘了加无参构造函数
标签: entity-framework