Currently I have created a Base Entity type that all my entities will derive from.
public abstract class BaseEntity
{
/// <summary>
/// Key Field for all entities
/// </summary>
///
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
/// <summary>
/// Date entity was created
/// </summary>
public DateTime DateCreated { get; set; }
/// <summary>
/// Last date Modified
/// </summary>
public DateTime DateModified { get; set; }
/// <summary>
/// keep track of Row Version used for concurrency
/// </summary>
[Timestamp]
public Byte[] RowVersion { get; set; }
}
}
I am thinking of decoupling my model from entity framework so it is not reliant on it. I’d like to have another project that is for my EF implementation. So, I would like to include the mappings in that project that will make up the relationships in my model.
Since my BaseEntity class is an abstract class what is the best way for me to keep my [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] and [TimeStamp] attributes so that it will apply to all my derived entities using the fluent API and separate mapping file? I don't think I can setup the modeler to add the BaseEntity mapping becasue it is an abstract class. Should I create an interface that has all my base functionality and repeat the mappings for all my entities?
I am using the EntityTypeConfiguration class and creating separate mapping classes for all my entities.