Entity framework core 使用IncludeThen时System.ArgumentNullException异常
我有一个代码优先的模型:我试图使用Entity framework core 使用IncludeThen时System.ArgumentNullException异常,entity-framework-core,Entity Framework Core,我有一个代码优先的模型:我试图使用Include()和IncludeThen()并获得一个系统。ArgumentNullException 以下是实体(如果您想要更多的模型,请告诉我): 以下是堆栈跟踪: 位于System.Linq.Expressions.Expression.New(ConstructorInfo构造函数,IEnumerable1参数) 位于Microsoft.Data.Entity.Metadata.Internal.EntityMaterializerSource.Cre
Include()
和IncludeThen()
并获得一个系统。ArgumentNullException
以下是实体(如果您想要更多的模型,请告诉我):
以下是堆栈跟踪:
位于System.Linq.Expressions.Expression.New(ConstructorInfo构造函数,IEnumerable1参数)
位于Microsoft.Data.Entity.Metadata.Internal.EntityMaterializerSource.CreateMeterialeExpression(entityType entityType,Expression valueBufferExpression,Int32[]indexMap)
在Microsoft.Data.Entity.Query.ExpressionVisitors.Internal.MaterialerFactory.CreateMeterializer(entityType entityType,SelectExpression SelectExpression,Func
3 projectionAdder,IQuerySource querySource)
在Microsoft.Data.Entity.Query.ExpressionVisitors.Internal.IncludeExpressionVisitor.d_u13.MoveNext()中
位于System.Collections.Generic.List1..ctor(IEnumerable
1集合)
在System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable1可枚举)
位于System.Linq.Expressions.Expression.NewArrayInit(类型类型,IEnumerable
1初始值设定项)
位于Microsoft.Data.Entity.Query.ExpressionVisitors.Internal.IncludeExpressionVisitor.VisitMethodCall(MethodCallExpression表达式)
位于System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor)
在Microsoft.Data.Entity.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(表达式)中
在Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.IncludeNavigations(IncludeSpecification IncludeSpecification,类型resultType,LambdaExpression accessorLambda,布尔查询资源请求跟踪)
位于Microsoft.Data.Entity.Query.EntityQueryModelVisitor.IncludeNavigations(QueryModel QueryModel,IReadOnlyCollection1 includeSpecifications)
在Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.IncludeNavigations(QueryModel QueryModel,IReadOnlyCollection
1 includeSpecifications)中
位于Microsoft.Data.Entity.Query.EntityQueryModelVisitor.IncludeNavigations(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_uuDisplayClass18_01.b_u0()中
在Microsoft.Data.Entity.Query.Internal.CompiledQueryCache.GetOradQuery[TResult](对象缓存键,Func
1编译器)
位于Microsoft.Data.Entity.Query.Internal.QueryCompiler.CompileQuery[TResult](表达式查询)
在Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](表达式查询)中
在Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](表达式)中
at Remotion.Linq.QueryableBase1.GetEnumerator()
在Microsoft.Data.Entity.EntityFrameworkQueryableExtensions.IncludableQueryable上
在c:\Users\ehasson\Source\Workspaces\Marketing\WeatherMonitoringConsole\Program.c\uu DisplayClass0\u 0.d.MoveNext()中
问题是每个实体都需要一个默认构造函数。问题是每个实体都需要一个默认构造函数
public class Area
{
public Area()
{
Geocode = new List<Geocode>();
}
public int AreaId { get; set; }
public int InfoId { get; set; }
public string AreaDescription { get; set; }
public string Polygon { get; set; }
public string Circle { get; set; }
public List<Geocode> Geocode { get; set; }
public string Altitude { get; set; }
public string Ceiling { get; set; }
}
public class Geocode
{
public Geocode(string valueName, string value
)
{
ValueName = valueName;
Value = value;
}
public int GeocodeId { get; set; }
public int AreaId { get; set; }
public string ValueName { get; set; }
public string Value { get; set; }
}
context.Alerts.Include(f => f.Infos)
.ThenInclude(f => f.Areas)
.ThenInclude(f => f.Geocode);// When I comment out this line it does not error, just doesn't load the Geocode navigation property.