I use the EF 4 + POCOs database first. Since EF does not have an easy way to declare that incoming DateTimes are in UTC, I moved the property from an automatically generated file to a partial class to another file.
private DateTime _createdOn; public virtual System.DateTime CreatedOn { get { return _createdOn; } set { _createdOn = (value.Kind == DateTimeKind.Unspecified) ? _createdOn = DateTime.SpecifyKind(value, DateTimeKind.Utc) : value; } }
However, now, every time I update the model, automatic properties are again created in the T4 gene. Of course, this leads to the following compilation error: "Type" Foo "already contains a definition for" CreatedOn ".
Is there a way to tell EF not to generate this property and let me handle it myself?
Update
Thanks for all the answers ...
I created a new custom property with a different name.
public virtual System.DateTime CreatedOnUtc { get { return (CreatedOn.Kind==DateTimeKind.Unspecified) ? DateTime.SpecifyKind(CreatedOn, DateTimeKind.Utc) : CreatedOn; } set { CreatedOn = (value.Kind == DateTimeKind.Unspecified) ? CreatedOn = DateTime.SpecifyKind(value, DateTimeKind.Utc) : value; } }
I also set all the setters and receivers of the automatically generated property to Private, except for the properties that I needed to use in the Linq-to-Entities (sigh) request. In these cases, I installed these getters on the internal ones.
I am sure that a drop-down menu has been shown in DateTime types to indicate which DateTime "view" should treat EF as EF. This would save hours and additional complication.
c # entity-framework entity-framework-4 poco
Jason Aug 03 '11 at 18:01 2011-08-03 18:01
source share