Created
September 12, 2012 17:51
-
-
Save dreadjr/3708558 to your computer and use it in GitHub Desktop.
Entity Framework 5 Code First CustomEntityTypeConfiguration to force datetime2 usage on common inherited fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomEntityTypeConfiguration<T> : EntityTypeConfiguration<T> where T : EntityBase | |
{ | |
public CustomEntityTypeConfiguration() | |
{ | |
this.Property(t => t.CreatedDate).HasColumnType("datetime2"); | |
} | |
} | |
// usage | |
public class EntityBase { | |
public long Id {get;set;} | |
public DateTime CreatedDate {get;set;} | |
} | |
public class SomeEntity : EntityBase { | |
public string Name {get;set;} | |
} | |
public class SomeEntityConfiguration : CustomEntityTypeConfiguration<SomeEntity> | |
{ | |
public SomeEntityConfiguration() | |
{ | |
//configure key and properties | |
this.HasKey(c => c.Id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment