Core scaffolding Oracle DB will give multiple ID(primary key's) as result

1

When I scaffold this Oracle DB (database -first) and it generates me all models, contexts, FK relations ect. But it gives me an error in the context when I start Querying. (simple things as select * from (any Table))

The follow error comes up.

System.InvalidOperationException

HResult=0x80131509

Message=The properties 'Address.AddressId', 'Address.AddressItemId' are configured to use 'Identity' value generator and are mapped to the same table '[DBName].ADDRESS'. Only one column per table can be configured as 'Identity'. Call 'ValueGeneratedNever' for properties that should not use 'Identity'.

Source=Oracle.EntityFrameworkCore

StackTrace:

at Oracle.EntityFrameworkCore.Internal.OracleModelValidator.ValidateSharedColumnsCompatibility(IReadOnlyList`1 mappedTypes, String tableName)

at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.ValidateSharedTableCompatibility(IModel model)

at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model)

at Oracle.EntityFrameworkCore.Internal.OracleModelValidator.Validate(IModel model)

at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ValidatingConvention.Apply(InternalModelBuilder modelBuilder)

at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder)

at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder)

at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.Validate()

at Microsoft.EntityFrameworkCore.ModelBuilder.FinalizeModel()

at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)

at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass5_0.b__1()

at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)

at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)

at System.Lazy`1.CreateValue()

at System.Lazy`1.get_Value()

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.b__7_2(IServiceProvider p)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProviderEngineScope scope)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(IServiceCallSite callSite, ServiceProviderEngineScope scope)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.b__0(ServiceProviderEngineScope scope)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.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.get_DbContextDependencies()

at Microsoft.EntityFrameworkCore.DbContext.get_Model()

at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()

at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.CheckState()

at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()

at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Linq.IQueryable.get_Provider()

at System.Linq.Queryable.Count[TSource](IQueryable`1 source)

at OracleConsoleApp.Program.Main(String[] args) in C:\GitPlayGround\OracleConsoleApp\OracleConsoleApp\Program.cs:line 47

I need to use the FK connections in this complex structure. I have no experience with Oracle, nor with Oracle.EntityFrameworkCore (2.2.6, application core 2.2)
Can anyone advise me what to do, Can't find a clue to start to solve this.

oracle
entity-framework-core
asp.net-core-scaffolding
asked on Stack Overflow Oct 26, 2019 by Dinand • edited Oct 29, 2019 by Dinand

1 Answer

4

After a deep research, my colleague came with the solution. In Oracle generated value's work different. With the database first it sets the data annotation ValueGeneratedOnAdd();.

This is not a working model and context.

So selective deleting this ValueGeneratedOnAdd() will result in a working result and solves the problem.

answered on Stack Overflow Oct 29, 2019 by Dinand

User contributions licensed under CC BY-SA 3.0