Initial Migration after Update from RC2 to RTM throwing error
I previously used RC2 and after installing VS2015.3 I now installes the EF Core 1.0 RTM and get the following error:
The key {'TempId'} contains properties in shadow state and is referenced by a relationship from 'SolidColorBrush' to 'Score.RowColor'. Configure a non-shadow principal key for this relationship.
Funfact: TempId is never used in any of my classes and the entry RowColor in class Score is flagged as [NotMapped]:
[NotMapped]
public SolidColorBrush RowColor { get; set; }
The full error:
Add-Migration migr1
System.InvalidOperationException: The key {'TempId'} contains properties in shadow state and is referenced by a relationship from 'SolidColorBrush' to 'Score.RowColor'. 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.Metadata.Internal.Model.Validate()
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Validate()
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass14_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.LazyRef`1.get_Value()
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.<>c.<AddEntityFramework>b__0_4(IServiceProvider p)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass12_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.<>c__DisplayClass7_0.<ConfigureContextServices>b__9(IServiceProvider _)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider 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.ServiceProvider.<>c__DisplayClass12_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.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The key {'TempId'} contains properties in shadow state and is referenced by a relationship from 'SolidColorBrush' to 'Score.RowColor'. Configure a non-shadow principal key for this relationship.
My project.json:
{
"dependencies": {
"LiveSDK": "5.6.3",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.0",
"Microsoft.OneDriveSDK": "1.1.47"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
The two types are probably not the same in the 2 different classes (i had the issue when one was int and the other was long)
@VikSab I'm sorry, I don't quite understand what you mean by that.
Update after removing
[NotMapped]
public SolidColorBrush RowColor { get; set; }
from class Score, I just got the same error message for another class implementing the exact same lines of code above - why does this happen, even they are flagged as [NotMapped]?
I don't know, if this helps, but when I remove the App.config file, that is mentioned here, I get the following error instead:
System.TypeLoadException: Could not load type 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Hey,
We'll need something that we can run in order to reproduce and debug this one. I tried a simple model with a SolidColorBrush property, which failed with the exception you see when it was mapped, but adding the [NotMapped] attribute resolved the issue.
When filing issues, if possible, try to follow the template we provide - which includes the following section:
Steps to reproduce
Ideally include a complete code listing that we can run to reproduce the issue. Alternatively, you can provide a project/solution that we can run.
BTW for anyone else looking at this one, SolidColorBrush is from System.Windows.Media in a WPF app.
~Rowan
@rowanmiller I just created a more clear example with better caption and test class here #5945