I have an Code First model: I am attempting to use Include()
and IncludeThen()
and get a System.ArgumentNullException
.
Here are the entities (let me know if you'd like more of the model):
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; }
}
Here is the calling code:
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.
Here is a stack trace:
at System.Linq.Expressions.Expression.New(ConstructorInfo constructor, IEnumerable
1 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, Func
3 projectionAdder, IQuerySource querySource) at Microsoft.Data.Entity.Query.ExpressionVisitors.Internal.IncludeExpressionVisitor.d__13.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable
1 collection) at System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable1 enumerable) at System.Linq.Expressions.Expression.NewArrayInit(Type type, IEnumerable
1 initializers) at Microsoft.Data.Entity.Query.ExpressionVisitors.Internal.IncludeExpressionVisitor.VisitMethodCall(MethodCallExpression expression) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at Microsoft.Data.Entity.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression expression) at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.IncludeNavigations(IncludeSpecification includeSpecification, Type resultType, LambdaExpression accessorLambda, Boolean querySourceRequiresTracking) at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.IncludeNavigations(QueryModel queryModel, IReadOnlyCollection1 includeSpecifications) at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.IncludeNavigations(QueryModel queryModel, IReadOnlyCollection
1 includeSpecifications) at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.IncludeNavigations(QueryModel queryModel) at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel) at Microsoft.Data.Entity.Storage.Database.CompileQuery[TResult](QueryModel queryModel) --- End of stack trace from previous location where exception was thrown --- at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass18_01.<CompileQuery>b__0() at Microsoft.Data.Entity.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func
1 compiler) at Microsoft.Data.Entity.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query) at Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at Remotion.Linq.QueryableBase1.GetEnumerator() at Microsoft.Data.Entity.EntityFrameworkQueryableExtensions.IncludableQueryable
2.GetEnumerator() at WeatherMonitoringConsole.Program.<>c__DisplayClass0_0.<b__0>d.MoveNext() in C:\Users\ehasson\Source\Workspaces\Marketing\WeatherMonitoring\WeatherMonitoringConsole\Program.cs:line 32