0
votes

I have an Code First model: 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, 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) at Microsoft.Data.Entity.Query.ExpressionVisitors.Internal.IncludeExpressionVisitor.d__13.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable1 enumerable) at System.Linq.Expressions.Expression.NewArrayInit(Type type, IEnumerable1 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, IReadOnlyCollection1 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, Func1 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.IncludableQueryable2.GetEnumerator() at WeatherMonitoringConsole.Program.<>c__DisplayClass0_0.<b__0>d.MoveNext() in C:\Users\ehasson\Source\Workspaces\Marketing\WeatherMonitoring\WeatherMonitoringConsole\Program.cs:line 32

1

1 Answers

3
votes

The problem was I needed a default constructor on each entity.