Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that all leaves in the entity types hierarchy are concrete #4793

Closed
anpete opened this issue Mar 14, 2016 · 1 comment
Closed

Validate that all leaves in the entity types hierarchy are concrete #4793

anpete opened this issue Mar 14, 2016 · 1 comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@anpete
Copy link
Contributor

anpete commented Mar 14, 2016

Model:

    public class StarWarsContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            => optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=GrephQL.StarWars;Trusted_Connection=True;");

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Character>();
        }
    }

    public abstract class Character
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }

    public class Human : Character
    {
        public string HomePlanet { get; set; }
    }

    public class Droid : Character
    {
        public string PrimaryFunction { get; set; }
    }

Query:

data.Set<Character>().SingleAsync(h => h.Id == "3");

Error:

An exception of type 'System.IndexOutOfRangeException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code

Additional information: Index was outside the bounds of the array.

   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.MaterializerFactory.CreateMaterializer(IEntityType entityType, SelectExpression selectExpression, Func`3 projectionAdder, IQuerySource querySource)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.CreateShaper(Type elementType, IEntityType entityType, SelectExpression selectExpression)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitEntityQueryable(Type elementType)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.EntityQueryableExpressionVisitor.VisitConstant(ConstantExpression constantExpression)
   at System.Linq.Expressions.ConstantExpression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause, QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause, QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
   at Remotion.Linq.Clauses.MainFromClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileAsyncQuery[TResult](QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass20_0`1.<CompileAsyncQuery>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQuery[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, LambdaExpression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken)
   at GrefQL.Tests.Query.StarWarsQuery.<>c__DisplayClass0_0.<.ctor>b__0(ResolveFieldContext context) in C:\Dev\GrefQL\test\GrefQL.Tests\Query.cs:line 58
   at GraphQL.DocumentExecuter.<ResolveField>d__8.MoveNext() in C:\Home\projects\graphql-dotnet\src\GraphQL\Execution\DocumentExecuter.cs:line 173
@rowanmiller
Copy link
Contributor

We should catch that there are non concrete types in model validation

@AndriySvyryd AndriySvyryd changed the title ArrayOutOfBounds when creating relational materializer Validate that all leaves in the entity types hierarchy are concrete Mar 29, 2016
AndriySvyryd added a commit that referenced this issue Apr 1, 2016
Validate all discriminator values are unique
Reset discriminator values when discriminator property changes

Fixes #4793
Fixes #4170
Fixes #4776
AndriySvyryd added a commit that referenced this issue Apr 1, 2016
Validate all discriminator values are unique
Reset discriminator values when discriminator property changes

Fixes #4793
Fixes #4170
Fixes #4776
@AndriySvyryd AndriySvyryd removed their assignment Apr 1, 2016
@AndriySvyryd AndriySvyryd modified the milestones: 1.0.0-rc2, 1.0.0 Apr 1, 2016
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers modified the milestones: 1.0.0-rc2, 1.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

4 participants