Calling OwnsOne on navigation which implements ICollection throws NullRef
Using a complex type did work with 2.1.0-preview1-final but broke with the latest preview.
Exception message:
Object reference not set to an instance of an object.
Stack trace:
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.FindRelationshipCandidates(InternalEntityTypeBuilder entityTypeBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.DiscoverRelationships(InternalEntityTypeBuilder entityTypeBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.Apply(EntityType entityType, MemberInfo navigationProperty)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.Apply(InternalEntityTypeBuilder sourceEntityTypeBuilder, InternalEntityTypeBuilder targetEntityTypeBuilder, String navigationName, MemberInfo propertyInfo)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnNavigationRemoved(InternalEntityTypeBuilder sourceEntityTypeBuilder, InternalEntityTypeBuilder targetEntityTypeBuilder, String navigationName, MemberInfo memberInfo)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.RunVisitor.VisitOnNavigationRemoved(OnNavigationRemovedNode node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnNavigationRemovedNode.Accept(ConventionVisitor visitor)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.Visit(ConventionNode node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionScope.Accept(ConventionVisitor visitor)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.Visit(ConventionNode node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionScope.Accept(ConventionVisitor visitor)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.Visit(ConventionNode node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Dispose()
at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.OwnsOneBuilder[TRelatedEntity](PropertyInfo navigation)
at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.OwnsOne[TRelatedEntity](Expression`1 navigationExpression)
at NullReferenceAtFindRelationshipCandidates.DatabaseContext.<>c.<OnModelCreating>b__1_0(EntityTypeBuilder`1 e) in c:\users\alexander.herold.accenon\source\repos\NullReferenceAtFindRelationshipCandidates\NullReferenceAtFindRelationshipCandidates\DatabaseContext.cs:line 19
at Microsoft.EntityFrameworkCore.ModelBuilder.Entity[TEntity](Action`1 buildAction)
at NullReferenceAtFindRelationshipCandidates.DatabaseContext.OnModelCreating(ModelBuilder modelBuilder) in c:\users\alexander.herold.accenon\source\repos\NullReferenceAtFindRelationshipCandidates\NullReferenceAtFindRelationshipCandidates\DatabaseContext.cs:line 17
at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass5_0.<GetModel>b__1()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
Steps to reproduce
Clone https://github.com/Alexxtheonly/NullReferenceAtFindRelationshipCandidates
In Test.cs run test ShouldThrowNullReference()
Further technical details
EF Core version: 2.1.0-preview2-final Database Provider: InMemory, but doesn't matter Operating system: Windows 10 IDE: Visual Studio 15.6.6
@smitpatel Was this working for you in 2.0 versions of EF Core?
@Alexxtheonly Last comment was supposed to be to you: Was this working for you in 2.0 versions of EF Core?
@ajcvickers I've never tested this part of my code with 2.0. If i recall correctly i had another error that led me to use 2.1.0-preview1-final.
update: Tested https://github.com/Alexxtheonly/NullReferenceAtFindRelationshipCandidates/tree/TestWith2.0 with 2.0. It works.