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

Cannot have keys other than those declared on the root type #5309

Closed
peirens-bart opened this issue May 9, 2016 · 8 comments
Closed

Cannot have keys other than those declared on the root type #5309

peirens-bart opened this issue May 9, 2016 · 8 comments

Comments

@peirens-bart
Copy link

peirens-bart commented May 9, 2016

I'm having these error when running:
dnx ef migrations add BT0001 -c "ApplicationContext" -p "BookerTools.Database.EF" -v

I can't find why I'm having this error,
I added the project that I'm using, Can someone tell me what I'm doing wrong or what that I forget to do.
Many thanks in advanced.

@ilkertskn
Copy link

@peirens-bart
Copy link
Author

peirens-bart commented May 10, 2016

ilkertskn, The problem is not the command but the exception message that I get.

If I comment out the "MyDatabase" models and mappers in the context, the command is creating the migration file.
If I uncomment the "MyDatabase" models and mappers I got the exception

Finding DbContext classes...
Using context 'ApplicationContext'.
System.InvalidOperationException: The derived type 'BookerTools.Business.Security.User' cannot have keys other than
   at Microsoft.Data.Entity.Metadata.Internal.EntityType.AddKey(IReadOnlyList`1 properties)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.HasKey(IReadOnlyList`1 properties, Configur
   at Microsoft.Data.Entity.Metadata.Builders.EntityTypeBuilder`1.HasKey(Expression`1 keyExpression)
   at BookerTools.Database.EF.Mappers.FrameworkModelsMapper.MapEntity[T](EntityTypeBuilder`1 builder)
   at BookerTools.Database.EF.Mappers.FrameworkModelsMapper.MapAggregate[T](EntityTypeBuilder`1 builder)
   at BookerTools.Database.EF.Mappers.FrameworkModelsMapper.MapAddressAggregate[T](EntityTypeBuilder`1 builder)
   at BookerTools.Database.EF.Mappers.SecurityModelsMapper.MapUser(EntityTypeBuilder`1 builder)
   at Microsoft.Data.Entity.ModelBuilder.Entity[TEntity](Action`1 buildAction)
   at BookerTools.Database.EF.Mappers.SecurityModelsMapper.Map(ModelBuilder builder)
   at BookerTools.Database.EF.Context.ApplicationContext.OnModelCreating(ModelBuilder modelBuilder)
   at Microsoft.Data.Entity.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder convent
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Data.Entity.Internal.DbContextServices.CreateModel()
   at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite.Invoke(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provid
   at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider pro
   at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextT
   at Microsoft.Data.Entity.Commands.Program.Executor.<>c__DisplayClass6_0.<AddMigration>b__0()
   at Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action)
The derived type 'BookerTools.Business.Security.User' cannot have keys other than those declared on the root type.

For me the message is strange since the User is not part of the "MyDatabase" models and if that model is the cause of the error it should throw the same exception if "MyDatabase" models and mappers are not included.

I think the problem is that some models have the same base class in Framework, and I read about not using the same property names in inheritance but the message it not saying that.
I understand the message as User has a different Primary key then the base class, what is not the case.
But I have no idea what is causing the exception.

@rowanmiller
Copy link
Contributor

Looks like a dupe of #3727 which was fixed in RC2. Can you retry on the RC2 release.

Closing as we are pretty confident that this is resolved in RC2, please reply if not and we will reopen.

@peirens-bart
Copy link
Author

I was not able to test RC2, the dependency" Microsoft.EntityFrameworkCore.SqlServer 1.0.0-rc2-final" and "Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final" is not supported.

I'm only using dnxcore50 as runtime.

@rowanmiller
Copy link
Contributor

Yeah you would need to move your whole project to RC2, not just the EF parts. DNX is retired in favor of .NET Core in RC2.

Here are the applicable docs:

@peirens-bart
Copy link
Author

Rowan

I'm not totally understanding the new .Net core, is it possible to give an example of a project.json file that is using EF rc2 en is not an mvc project but a class library.

Just to give more context,
I'm using VS 2015 pro 14.0.25123.00 Update 2 and I'm keep having the same error, that the rc2 versions are not supported.

@smitpatel
Copy link
Contributor

Tools won't work in class library project see #5320
this is sample project.json for .NET Core class library project to use SqlServer provider

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
  },

  "frameworks": {
    "netstandard1.3": {
      "imports": ["portable-net451+win81"]
    }
  }
}

@peirens-bart
Copy link
Author

All thanks for the answers,
But we are going to wait until there is a stable version that support more project types.

For the initial issue I found a work-a-round that is using rc1.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants