 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

February 24th, 2012, 12:53 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
utc date time
Hello Imar,
While storing review I was thinking that why use always system date time using getdate() and not the utc date. For this I changed default value to getutcdate() in both fields CreateDateTime and UpdateDateTime in Reviews table and updated the edmx file, and removed the lines which explicitly stores the date time for review.
Review myReview;
if (_id == -1) // Insert new item
{
myReview = new Review();
//myReview.CreateDateTime = DateTime.Now;
//myReview.UpdateDateTime = myReview.CreateDateTime;
myEntities.AddToReviews(myReview);
}
But it was giving error that datetime2 type value can not be converted into datetime type value. So I changed datatype of both date time field to datetime2(7) and it is working well now.
The only problem is that it is storing default date time value 1/1/0001 12:00 AM and not the real utc date. Please tell me how to store real utc date values
Thanks
|
|

February 25th, 2012, 03:39 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
|
|
use UtcNow instead of Now:
Code:
if (_id == -1) // Insert new item
{
myReview = new Review();
myReview.CreateDateTime = DateTime.UtcNow;
myReview.UpdateDateTime = myReview.CreateDateTime;
myEntities.AddToReviews(myReview);
}
datetime2 type is used to store datetime values with no limitation of range values. for example in Hijri date we use 1391/12/05 today instead of 2012/Mar/24 so in earlier versions we could not store date values and we was forced to convert our date values to Gregorian dates. but now there is no limitation with datetime2.
__________________
happy every time, happy every where
Reza Baiat
|
|

February 25th, 2012, 09:03 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Quote:
|
use UtcNow instead of Now:
|
I'm aware of this fact, but I do not want to set the date in code behind file. Any other method?
Thanks
|
|

February 26th, 2012, 11:44 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Please someone help me...
|
|

February 28th, 2012, 11:46 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
|
|
Hi there
GetUtcDate() in sql returns the UtcTime. it works fine as it should. but I think there are some problems with edmx update. I've faced some problems with edmx updating, and I was forced to reCreate the edmx file.
__________________
happy every time, happy every where
Reza Baiat
|
|

February 28th, 2012, 02:07 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Hi Reza,
I did not delete and recreated edmx file, but yes deleted the corresponding table, saved edmx and then added again that table and saved edmx but it did not work.
How this problem can be solved?
Thanks
|
|

February 29th, 2012, 04:07 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
|
|
Hi there
I think CreateDateTime and UpdateDateTime fields of your table are not nullable. so when Entity Framework wants to set the values, uses it's .Net default values (new DateTime()). Try to set these two fields as nullable, set default value to GetUtcDate(), update edmx file and then test below codes
Code:
if (_id == -1) // Insert new item
{
myReview = new Review();
myEntities.AddToReviews(myReview);
}
__________________
happy every time, happy every where
Reza Baiat
|
|

February 29th, 2012, 05:24 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
No Luck,
Null is being stored in table
|
|

March 1st, 2012, 02:36 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Hi Imar, Kindly say something on this topic.
|
|

March 1st, 2012, 02:37 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Does it work when you add a record in the table directly?
I would add a constructor to the class and set the value from there in code.....
Imar
|
|
 |
|