c# - Entity Framework 6.1 and Member Hiding using New Keyword -


I have a group that implements an interface called ICreatableEntity is the definition:

  Public Interface ICTTableInti {int CreatedById {get; Set; } Created by Employee {Received; Set; } Date Created Date Time {Receive; Set; }}   

A specific unit, employee , requires a little change because the first record can not be the creator and thus I need to clear the column is . So, I just tried to hide the inherited member using the new keyword:

  the public new int? Built-in BIID {Received; Set; }   

And all this works, the compiler likes it and all, but when the model is being generated by EF, it crashes with an error The item is already present in the metadata collection . I'm guessing, EF probably first adds my override, then earns the base to add property, even though I'm trying to hide it, and when it crashes.

Update: I have tried to drop it and changed it to Fluent API configuration in alternate, which also compiles properly, but again crashing again It happens when my seed data is being inserted because I still leave it effectively.

Is there any alternative solution for this, that I do not need to flip the argument and make it negligible for everything, and then add dozens of Fluent API configurations to tell EF, it really does not Need a place?

Update: To give just a bit more information, the database is being rebuilt by the EF every time because I'm not using anything in the past.

I have a solution that I am quite content with it. It hits me that when a foreign key specifies, I can either use the HasForeignKey () or map () with the Fluent API. HasForeignKey () needs to specify the property already present on the unit, but map () allows you to specify the name of the property EF Key will generate in Before using either methods, the relationship will already be configured as necessary or optional ( HasRequired () , HasOptional () ), account for instability Will happen.

So, I did this and removed clear asset announcements from my interface which was magically solving the entire issue. It also helps me start using the base configuration class , Which takes a heavy load for the institutions implementing my interface employee for configuration I once had to override a specific method and it was good to go.

Here are some of the things that have a small version of the base configuration class.

  Internal class configuration & lt; TENTity & gt; : EntityTypeConfiguration & lt; TEntity & gt; Where Tementi: Class, IcTableTT, New () {Secure Virtual Zero Configuration () {this.Configure (ConfigurationParameters.Default); } Configure protected virtual zeroes (configuration parameter parameters) {this. Configurable control reliance (parameter. Created by valid cadence denate); } #region Relationship Configuration Virtual Zero ConfigureCreatableRelationships Protected (bool willCascadeOnDelete) {this.HasRequired (t = & gt; t.CreatedBy). .WithMany () Map (M = & gt; m.MapKey ("CreatedById")). WillCascadeOnDelete (willCascadeOnDelete); } #registration   

and override EmployeeConfiguration in my class:

  Internal seal class EmployeeConfiguration: Configuration's & lt; Employee & gt; {Protected Override Zero ConfigureCreatableRelationships (bool willCascadeOnDelete) {this.HasOptional (t = & gt; t.CreatedBy) .WithMany () Map (M = & gt; m.MapKey ("CreatedById")); }}   

I hope this helps someone in the future.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -