0

How can I create an entity, with a navigation property to another entity, but without creating the Foreign Key.

Ex:

class EntityType { Id, Code, Description }

class Entity { Id, Name, Age, EntityType, EntityTypeId}

class EntityHistory { Id, EntityId, Name, Age, EntityType, EntityTypeId }

In my Entity class, I want the normal navigation property and foreign key. But in the EntityHistory, I want the navigation property, I want to have the EntityTypeId, but I don't want to create the relation in the database between EntityHistory and the EntityType.

In my model, EntityHistory is a audit table from Entity, it is only written via Entity Trigger and in this scenario, it doesn't make much sense to create the relation in the database (For example it slows too much the bulk insert of million's of records) But I want the navigation property because I want to retrieve the information to the user interface.

So my ultimate goal is just to prevent SQL Server to check the constraint in the Foreign Key.

Thks

1 Answers1

0

You will have to create both ends of the relationship in your configuration, like these scenarios:

1=>many:

HasRequired(charac => charac.Movie)
    .WithMany(movie => movie.Characters);

many=>1:

HasMany(movie => movie.Characters)
    .WithRequired(character => character.Movie);

In depth info here.

Mike Cole
  • 14,474
  • 28
  • 114
  • 194