Was Pluggable conventions removed from the EF 5 release, i saw it in the pre releases? Looking for a way to force ef code use datetime2 by convention, so don't need to explicit map each column of every entity.
Came across a similar issue. I have a generic repository that has a BaseEntity similar to yours.
public abstract class BaseEntity
{
public int Id { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
}
and then each entity is derived from the base.
public class MyEntity: BaseEntity
{
public string Name{ get; set; }
public int prop1 { get; set; }
public int prop2 { get; set; }
}
I ended up setting the Created and Updated properties of the BaseEntity using a columm attribute like this:
public abstract class BaseEntity
{
[Key, Column(Order = 0)]
public int Id { get; set; }
[Column(TypeName = "datetime2")]
public DateTime Created { get; set; }
[Column(TypeName = "datetime2")]
public DateTime Updated { get; set; }
}
I looked at your solution at (http://dreadjr.blogspot.com/2012/09/entity-framework-5-code-first-datetime2.html) and it looks fine too, but it requires to have a specific configuration class for each entity. Anyways, I thought I'll share this with you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With