EF7 add migrations error when using NotMapped attribute in entity properties

asp.net-core c# code-first-migrations entity-framework entity-framework-core

Question

I am not able to use the [NotMapped] attribute on entity properties because the migration add command throws an error below;

Here is my POCO;

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.Entities
{
    public partial class Employer
    {
        public int EmployerId { get; set; }
        public bool? Blacklisted { get; set; }
        [NotMapped]
        public int TestProperty { get; set; }
    }
}

And this the exception message I get.

System.ArgumentNullException: Value cannot be null.
Parameter name: navigation
   at Microsoft.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnNavigationAdded(InternalRelationshipBuilder relationshipBuilder, Navigation navigation)
   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.Relationship(InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, String navigationToPrincipalName, String navigationToDependentName, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior, Boolean strictPrincipal, Boolean oldRelationshipInverted, String oldNavigationToPrincipalName, String oldNavigationToDependentName, ConfigurationSource configurationSource, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.ReplaceForeignKey(InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, String navigationToPrincipalName, String navigationToDependentName, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior, Boolean strictPrincipal, Boolean oldRelationshipInverted, ConfigurationSource configurationSource, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.ReplaceForeignKey(ConfigurationSource configurationSource, InternalEntityTypeBuilder principalEntityTypeBuilder, InternalEntityTypeBuilder dependentEntityTypeBuilder, String navigationToPrincipalName, String navigationToDependentName, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, Nullable`1 isUnique, Nullable`1 isRequired, Nullable`1 deleteBehavior, Boolean strictPrincipal, Boolean oldRelationshipInverted, Boolean runConventions)
   at Microsoft.Data.Entity.Metadata.Internal.InternalRelationshipBuilder.Navigations(String navigationToPrincipalName, String navigationToDependentName, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.Navigations(InternalRelationshipBuilder relationship, String navigationToPrincipalName, String navigationToDependentName, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.Relationship(InternalEntityTypeBuilder targetEntityTypeBuilder, PropertyInfo navigationToTarget, PropertyInfo inverseNavigation, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.FindRelationshipCandidates(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, String ignoredMemberName)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeMemberIgnored(InternalEntityTypeBuilder entityTypeBuilder, String ignoredMemberName)
   at Microsoft.Data.Entity.Metadata.Internal.InternalEntityTypeBuilder.Ignore(String memberName, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NotMappedMemberAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.InversePropertyAttributeConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, PropertyInfo navigationPropertyInfo, InversePropertyAttribute attribute)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.NavigationAttributeEntityTypeConvention`1.Apply(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
   at Microsoft.Data.Entity.Metadata.Internal.MetadataDictionary`2.GetOrAdd(Func`1 getKey, Func`1 createKey, Func`2 createValue, Func`2 onNewKeyAdded, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource)
   at Microsoft.Data.Entity.ModelBuilder.Entity(Type type)
   at Microsoft.Data.Entity.Infrastructure.ModelSource.FindSets(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.Data.Entity.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at Microsoft.Data.Entity.Infrastructure.ModelSource.<>c__DisplayClass8_0.<GetModel>b__0(Type k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Data.Entity.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at Microsoft.Data.Entity.Internal.DbContextServices.CreateModel()
   at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
   at Microsoft.Data.Entity.Internal.DbContextServices.get_Model()
   at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c.<AddEntityFramework>b__0_5(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.ServiceProviderExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.Data.Entity.Design.Internal.DesignTimeServicesBuilder.<>c__DisplayClass7_0.<ConfigureContextServices>b__8(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.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.Data.Entity.Commands.Program.Executor.<>c__DisplayClass6_0.<AddMigration>b__0()
   at Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action)
Value cannot be null.
Parameter name: navigation

And these are my package dependencies;

"dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.Core": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final",
    "EntityFramework.Relational": "7.0.0-rc1-final",
    "EntityFramework.Relational.Design": "7.0.0-rc1-final"
  },

Any idea about why I am not able to use the [NotMapped] attribute anywhere in my entity properties?

Update: As suggested by Don, using the Fluent-api instead of annotations works but I still want to use the annotations. My goal is to add the [NotMapped] attribute to the base entity so that I don't have to add it to the child entities.

This is what I am trying to accomplish;

Mapping the base Id property to the primary key of the entities without adding the Id column to the database.

public class EntityBase
{
   [NotMapped]
   public virtual int Id{ get; set; }
}

//Auto generated POCO
public partial class MyEntity
{
   //The primary key
   public virtual int MyEntityId{ get; set; }
}

//Partial class that I modify the auto generated Poco
public partial class MyEntity : EntityBase
{
    public override int Id 
    {
     get { return MyEntityId; } 
     set { MyEntityId = value; }
     }
}

Accepted Answer

Try to use Fluent-API

modelBuilder.Entity<Employer>().Ignore(e => e.TestProperty);


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why