Making sure that DateTime properties return DateTimeKind.Utc?

For our case it was impractical to always specify the DateTimeKind as stated previously: DateTime utcDateTime = DateTime. SpecifyKind(databaseDateTime, DateTimeKind. Utc) If you want to force all DateTime objects coming out of the database to be specified as UTC you'll need to add a T4 transform file and add additional logic for all DateTime and nullable DateTime objects such that they get initialized as DateTimeKind.

Utc I have a blog post which explains this step by step: aaroncoleman.net/post/2011/06/16/Forcing... In short: 1) Create the . Tt file for your . Edmx model 2) Open the .

Tt file and find the "WritePrimitiveTypeProperty" method 3) Replace the existing setter code. This is everything between the ReportPropertyChanging and the ReportPropertyChanged method callbacks with the following: if( ((PrimitiveType)primitiveProperty.TypeUsage. EdmType).

PrimitiveTypeKind == PrimitiveTypeKind. DateTime) { #> if( == new DateTime()) { = StructuralObject. SetValidValue(value); if(value!

= null) = DateTime. SpecifyKind(.Value, DateTimeKind. Utc); = DateTime.

SpecifyKind(, DateTimeKind. Utc); } else { = StructuralObject. SetValidValue(value); } = StructuralObject.

SetValidValue(value).

For our case it was impractical to always specify the DateTimeKind as stated previously: DateTime utcDateTime = DateTime. SpecifyKind(databaseDateTime, DateTimeKind. Utc); If you want to force all DateTime objects coming out of the database to be specified as UTC you'll need to add a T4 transform file and add additional logic for all DateTime and nullable DateTime objects such that they get initialized as DateTimeKind.

Utc I have a blog post which explains this step by step: aaroncoleman.net/post/2011/06/16/Forcing... In short: 1) Create the . Tt file for your . Edmx model 2) Open the .

Tt file and find the "WritePrimitiveTypeProperty" method. 3) Replace the existing setter code. This is everything between the ReportPropertyChanging and the ReportPropertyChanged method callbacks with the following: if( == new DateTime()) { = StructuralObject.

SetValidValue(value); if(value! = null) = DateTime. SpecifyKind(.Value, DateTimeKind.

Utc); = DateTime. SpecifyKind(, DateTimeKind. Utc); } else { = StructuralObject.

SetValidValue(value); } = StructuralObject. SetValidValue(value).

Great answer, thanks! – Sander Rijken Jun 18 at 19:44.

Yes, it would be possible to use a custom T4 template. You'd just have to adjust your property setters and getters. It might be easier to attempt a POCO approach; For EF1: code.msdn.microsoft.com/EFPocoAdapter/Re... For EF4: thedatafarm.com/blog/data-access/agile-e....

If you want to force all DateTime objects coming out of the database to be specified as UTC you'll need to add a T4 transform file and add additional logic for all DateTime and nullable DateTime objects such that they get initialized as DateTimeKind. 1) Create the . Tt file for your .

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions