Wrox Programmer Forums
|
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
 
Old December 18th, 2011, 04:44 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile 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...
 
Old December 18th, 2011, 08:42 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 18th, 2011, 09:19 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

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.
 
Old December 18th, 2011, 09:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It's probably not nullable in the database. Therefore, EF creates a non-nullable integer that defaults to 0.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 18th, 2011, 10:50 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

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...
 
Old December 18th, 2011, 11:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 18th, 2011, 01:19 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
edmx ClarkNaylor BOOK: Beginning ASP.NET 4 : in C# and VB 2 June 29th, 2010 01:20 PM
Code for Chpt.2-Wrox File Share is missing Default.aspx and Default.aspx.vb bzoni BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 October 23rd, 2009 02:39 PM
EDMX arivarasuk ASP.NET 3.5 Professionals 6 January 30th, 2009 10:30 AM
Default values? Raymie_C Access VBA 2 May 16th, 2005 11:48 AM
Default Values davest Access VBA 2 October 19th, 2004 05:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.