-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add-Migration error: The key {'TempId'} contains properties in shadow state and is referenced by a relationship #5984
Comments
You are trying to add The error is because it can't create a shadow property with a key to the parent. ( Maybe you can make it somehow work by adding a key explicit using Fluent API. Still, adding a SelectList entity (class owned by MVC) into your database model is not a good idea. disclaimer: I'm not very familiar with EF, so take everything said with a grain of salt. |
When you include navigation of type |
Given that |
In my following Model if I have the following the
Add-Migration
command works fine but if I replace datatype of StateName from string toList<SelectListItem>
I get the error shown below. I'm using latest ASP.NET Core 1.0 and VS2015-Update 3 on win 8.1. I've just added the following class in the Model of this MSDN tutorial:Error:
[System.InvalidOperationException: The key {'TempId'} contains properties in shadow state and is referenced by a relationship from 'SelectListGroup' to 'SelectListItem.Group'. Configure a non-shadow principal key for this relationship. at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.KeyConvention.Apply(InternalModelBuilder modelBuilder) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder) at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() at Microsoft.EntityFrameworkCore.Internal.LazyRef
1.get_Value()at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.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.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action
1 reporter) at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.<>c__DisplayClass0_0.<Configure>b__0() at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) The key {'TempId'} contains properties in shadow state and is referenced by a relationship from 'SelectListGroup' to 'SelectListItem.Group'. Configure a non-shadow principal key for this relationship. ](url)
The text was updated successfully, but these errors were encountered: