You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Conventions shouldn't try to set the base type for owned types #9536
@bubibubi Are you asking for inheritance of containment? If the former, can you add a bit more detail as to what the types look like and how you expect them to be mapped? If the latter, then you can already do:
publicclassFriend{publicFriend(){Address=newFullAddress();}publicintId{get;set;}publicstringName{get;set;}publicFullAddressAddress{get;set;}}publicclassLessThanFriend{publicLessThanFriend(){Address=newCityAddress();}publicintId{get;set;}publicstringName{get;set;}publicCityAddressAddress{get;set;}}publicclassCityAddress{publicstringCap{get;set;}publicstringCity{get;set;}}publicclassFullAddress:CityAddress{publicstringStreet{get;set;}}publicclassTestContext:DbContext{publicTestContext(DbContextOptionsoptions):base(options){}publicDbSet<Friend>Friends{get;set;}publicDbSet<LessThanFriend>LessThanFriends{get;set;}protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){base.OnModelCreating(modelBuilder);// This Address is a full address. The problem is heremodelBuilder.Entity<Friend>().OwnsOne(_ =>_.Address);// This Address is a city addressmodelBuilder.Entity<LessThanFriend>().OwnsOne(_ =>_.Address);}}
BaseTypeDiscoveryConvention shouldn't be running on OwnedTypes since they don't allow inheritance.
behavior in 2.0 using above code.
Unhandled Exception: System.InvalidOperationException: The dependent entity type 'Friend.Address#FullAddress' cannot have a base type.
at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.HasBaseType(EntityType entityType, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.HasBaseType(EntityType baseEntityType, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.BaseTypeDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.RunVisitor.VisitOnEntityTypeAdded(OnEntityTypeAddedNode node)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAddedNode.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 EFSampleApp.MyContext.OnModelCreating(ModelBuilder modelBuilder) in D:\code\EFSampleApp\EFSampleApp\Program.cs:line 55
at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelCustomizer.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__0(Object k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_1(IServiceProvider p)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass22_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_DatabaseCreator()
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureDeleted()
changed the title [-]Support for owned types inherithed from other owned types[/-][+]Conventions shouldn't try to set the base type for owned types[/+]on Aug 24, 2017
@ajcvickers in general I'm expecting that EF handles a hierarchy of classes as a single class.
About first question, I'm not expecting that all the properties of the assigned object are persisted.
Actually it does not work in that way (EF persists the properties of the class specified in OwnsOne and I think that it is a perfect behaviour).
About the second question I'm expecting that the columns of LessThanFriend are able to contain the properties of the class specified in OwnsOne (so the properties of CityAddress). In my example I called both the properties Address and is a little bit confusing.
Triage decision: for now, we will throw a better exception. Issue #9630 filed for future to actual map these types.
@bubibubi Thanks for the great feedback. We're not planning to support this now--see #9630--but you can workaround the issue by using only leaves for your owned types. For example:
Activity
ajcvickers commentedon Aug 23, 2017
@bubibubi Are you asking for inheritance of containment? If the former, can you add a bit more detail as to what the types look like and how you expect them to be mapped? If the latter, then you can already do:
bubibubi commentedon Aug 24, 2017
@ajcvickers I'd like to map something like this
smitpatel commentedon Aug 24, 2017
BaseTypeDiscoveryConvention shouldn't be running on OwnedTypes since they don't allow inheritance.
behavior in 2.0 using above code.
@AndriySvyryd
[-]Support for owned types inherithed from other owned types[/-][+]Conventions shouldn't try to set the base type for owned types[/+]ajcvickers commentedon Aug 25, 2017
@bubibubi Couple of additional questions:
bubibubi commentedon Aug 26, 2017
@ajcvickers in general I'm expecting that EF handles a hierarchy of classes as a single class.
About first question, I'm not expecting that all the properties of the assigned object are persisted.
Actually it does not work in that way (EF persists the properties of the class specified in OwnsOne and I think that it is a perfect behaviour).
About the second question I'm expecting that the columns of LessThanFriend are able to contain the properties of the class specified in OwnsOne (so the properties of CityAddress). In my example I called both the properties Address and is a little bit confusing.
Here the tables I'm expecting.
ajcvickers commentedon Aug 30, 2017
Triage decision: for now, we will throw a better exception. Issue #9630 filed for future to actual map these types.
@bubibubi Thanks for the great feedback. We're not planning to support this now--see #9630--but you can workaround the issue by using only leaves for your owned types. For example:
AndriySvyryd commentedon Feb 6, 2018
Fixed in 2507a80