c# - Entity Framework Table Per Class Inheritance -


I am trying to apply a history table for an entity in EF6.

I think the legacy will be one way to do this with the history table, which is a derivative type of the actual table unit, which has direct copies of all properties.

booking for my code first table unit config

  public class BookingEntityConfiguration:. EntityTypeConfiguration & LT; Bookings & gt; {Public Booking Centers () {Property (B = & gt; B Booking ID). Column order (0); HasKey (b = & new; {b.BookingId}); HasOptional (b = & gt; b.BookingType) .mind () .hareingen (c => c.BookingTypeId); }}   

BookingHistory for my code first table unit

  public class BookingHistoryTypeEntityConfiguration:. EntityTypeConfiguration & LT; BookingHistory & gt; {Public booking historyTip Entity Configuration () {Property (B = & gt; B Booking ID). Column order (0); Property (B = & gt; B. Booking Edition). Column order (0); HasKey (b = & new; {b.BookingId, b.BookingVersion}); Booking History: Booking {}   

My BookingHistory

Where Code> table does not occur in the related database, which includes these references for table entities:

  public DbSet   

Do I want to have an easy way of achieving? Which derivative unit (History table) creates a table in which the same column field is in the form of a base class unit, but with the change of key.

I appreciate your code above very naive, but I can not find a blog post similar to help.

The best approach is the basis type from where both the unit and its history unit inherit:

  Public Class BookingsContext: DbContext {Public DbSet & LT; Bookings & gt; Booking {receive; Set; } Public DbSet & lt; BookingHistory & gt; Booking history {receive; Set; } Protected Override Zero OnModelCreating (DbModelBuilder modelBuilder) {modelBuilder.Entity & LT; BookingBase & gt; () .HasKey (P => P.BookingId) .Property (P => P.BookingId) .HasDatabaseGeneratedOption (DatabaseGeneratedOption.Identity); Modelbuilder.Entity & lt; Bookings & gt; (). Map (M = & gt; {M.map Inherited Properties}; M. teotable ("booking");}); Modelbuilder.Entity & lt; BookingHistory & gt; (). Map (M => {M. Map Inherited Properties}; M. teotable ("booking history");}); }}   

You specify that both organizations should be mapped to separate tables. On top, the Map Inherited Portfolios tells the IP to map all kinds of properties as well as mappels on this table. The result is two completely independent tables that can be addressed by two different code

DbSet .

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -