Closed piyushparate1 closed 4 years ago
To reproduce this error, I need a database schema script like this.
Thanks for your reply! Attached the database schema script.
To reproduce this error, I need a database schema script like this.
i tries to deploy this script db schema as well! throwing the same kind of issue:
System.InvalidOperationException
HResult=0x80131509
Message=The entity type 'DynamicType1' cannot be marked as keyless because it contains a key.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.HasNoKey(Nullable1 keyless, ConfigurationSource configurationSource) at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.set_IsKeyless(Boolean value) at OdataToEntity.EfCore.DynamicDataContext.ModelBuilder.DynamicModelBuilder.CreateEntityType(ModelBuilder modelBuilder, String tableEdmName, Boolean isQueryType) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\ModelBuilder\DynamicModelBuilder.cs:line 65 at OdataToEntity.EfCore.DynamicDataContext.ModelBuilder.DynamicModelBuilder.Build(ModelBuilder modelBuilder) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\ModelBuilder\DynamicModelBuilder.cs:line 28 at OdataToEntity.EfCore.DynamicDataContext.DynamicDbContext.OnModelCreating(ModelBuilder modelBuilder) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\DynamicDbContext.cs:line 26 at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context) at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder) at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_3(IServiceProvider p) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor
2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor
2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>cDisplayClass1_0.
This exception was originally thrown at this call stack: [External Code] OdataToEntity.EfCore.DynamicDataContext.ModelBuilder.DynamicModelBuilder.CreateEntityType(Microsoft.EntityFrameworkCore.ModelBuilder, string, bool) in DynamicModelBuilder.cs OdataToEntity.EfCore.DynamicDataContext.ModelBuilder.DynamicModelBuilder.Build(Microsoft.EntityFrameworkCore.ModelBuilder) in DynamicModelBuilder.cs OdataToEntity.EfCore.DynamicDataContext.DynamicDbContext.OnModelCreating(Microsoft.EntityFrameworkCore.ModelBuilder) in DynamicDbContext.cs [External Code] OdataToEntity.EfCore.DynamicDataContext.DynamicTypeDefinitionManager.Create(OdataToEntity.EfCore.DynamicDataContext.ModelBuilder.DynamicMetadataProvider) in DynamicTypeDefinitionManager.cs OdataToEntity.EfCore.DynamicDataContext.DynamicMiddlewareHelper.CreateEdmModel(OdataToEntity.EfCore.DynamicDataContext.InformationSchema.ProviderSpecificSchema, OdataToEntity.EfCore.DynamicDataContext.InformationSchema.InformationSchemaMapping) in DynamicMiddlewareHelper.cs WebApplication1.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder, Microsoft.AspNetCore.Hosting.IWebHostEnvironment) in Startup.cs [External Code] WebApplication1.Program.Main(string[]) in Program.cs
Hi!
I am trying to create OData API via referring "OdataToEntity.EfCore.DynamicDataContext" project in my main .net core web application project.
Below is the Startup.cs Configure function:
But on running the project, it throwing me error in below code:
namespace OdataToEntity.EfCore.DynamicDataContext.ModelBuilder class DynamicModelBuilder private EntityType CreateEntityType(***) Line: entityTypeBuilder.Metadata.IsKeyless = true;
System.InvalidOperationException HResult=0x80131509 Message=The entity type 'DynamicType1' cannot be marked as keyless because it contains a key. Source=Microsoft.EntityFrameworkCore StackTrace: at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.HasNoKey(Nullableb0(ServiceProviderEngineScope scope)
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 OdataToEntity.EfCore.DynamicDataContext.DynamicTypeDefinitionManager.Create(DynamicMetadataProvider metadataProvider) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\DynamicTypeDefinitionManager.cs:line 55
at OdataToEntity.EfCore.DynamicDataContext.DynamicMiddlewareHelper.CreateEdmModel(ProviderSpecificSchema providerSchema, InformationSchemaMapping informationSchemaMapping) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\DynamicMiddlewareHelper.cs:line 12
at WebApplication1.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\OdataToEntity\sln\WebApplication1\Startup.cs:line 59
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>cDisplayClass4_0.b 0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>cDisplayClass13_0.b2(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>cDisplayClass0_0.g MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>cDisplayClass2_0.b0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>cDisplayClass0_0.b 0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.d__31.MoveNext()
1 keyless, ConfigurationSource configurationSource) at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.set_IsKeyless(Boolean value) at OdataToEntity.EfCore.DynamicDataContext.ModelBuilder.DynamicModelBuilder.CreateEntityType(ModelBuilder modelBuilder, String tableEdmName, Boolean isQueryType) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\ModelBuilder\DynamicModelBuilder.cs:line 65 at OdataToEntity.EfCore.DynamicDataContext.ModelBuilder.DynamicModelBuilder.Build(ModelBuilder modelBuilder) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\ModelBuilder\DynamicModelBuilder.cs:line 28 at OdataToEntity.EfCore.DynamicDataContext.DynamicDbContext.OnModelCreating(ModelBuilder modelBuilder) in C:\OdataToEntity\source\OdataToEntity.EfCore.DynamicDataContext\DynamicDbContext.cs:line 26 at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context) at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder) at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_3(IServiceProvider p) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor
2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor
2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>cDisplayClass1_0.