 |
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
|
|
|
|
|

December 18th, 2011, 04:44 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Default values not mapping into edmx file
Hi Imar,
Although we have set up the default values for createdatetime and updatedatetime in table schema but these default values are not mapped into edmx files. it shows only (None) under Default Value property for these fields in edmx file.
Why this happens and how a complete schema be mapped perfectly in edmx file ?
Thanks...
|
|

December 18th, 2011, 08:42 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It's just a default in the database, in case your code doesn't supply a value. It's not meant to be imported into the EDMX.
If you want a default in your code, create a partial class for your entity and set the default value in the default constructor.
Cheers,
Imar
|
|

December 18th, 2011, 09:19 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Thanks Imar,
But I have an extra field ViewCounts (bigint) in Reviews table, and have set a default value to 1 in Default Value or Binding Property.
When I inserted a new record without supplying any value for this column, the value got inserted was 0, and when I changed default value for this column in EDMX file to 1 then it inserted 1 in new record.
Why it got inserted 0 for the first case?
Thanks for link you posted.
|
|

December 18th, 2011, 09:35 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It's probably not nullable in the database. Therefore, EF creates a non-nullable integer that defaults to 0.
Imar
|
|

December 18th, 2011, 10:50 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
what a vast knowledge you have. yes it does not allow null values.
Is it ok to set 1 manually in edmx file for that field.
Thanks...
|
|

December 18th, 2011, 11:38 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You could, but it would be a hardcoded default value, not something dynamic like GetDate in case of dates. I prefer to use a partial class and set the behavior through code.
But isn't zero for a ViewCount exactly right?
Imar
|
|

December 18th, 2011, 01:19 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Quote:
|
I prefer to use a partial class and set the behavior through code.
|
Thanks...
Quote:
|
But isn't zero for a ViewCount exactly right?
|
hummm, I will change it...
|
|
 |
|