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 April 13th, 2011, 04:43 AM
Registered User
 
Join Date: Apr 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Try It Out Pages 555 to 561

Hi
Greetings to everyone

I have a problem with the try it out on pages 555 up to 561.
And i have two pottential problems:

In the table Review, where the Id column has (Is Identity) to Yes, when i try to add new review, this code shows up:
Cannot insert explicit value for identity column in table 'Review' when IDENTITY_INSERT is set to OFF. And it point to the:
mojaEntity.SaveChanges(); where mojaEntity is myEntity.

Another thing, looking like from dark side of the force,
if the (Is Identity) switched to No, and then i try add new review through AddEditReviewHandCoded.aspx, this error comes up:

Violation of PRIMARY KEY constraint 'PK_Review'. Cannot insert duplicate key in object 'dbo.Review'. The duplicate key value is (0).
The statement has been terminated.

How i can fix it?
~Thanks very much for your help
 
Old April 13th, 2011, 04:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

What this looks like is that you set the Identity field at the database level *after* you created the Entity Framework mode. This way, EF doesn't know the column is generated by the data store and tries to submit its underlying value instead (which is zero as the default for an integer) when you save the changes to the data.

There are a few ways to fix it:

1. Delete the tables from the EF diagram and add them again.

2. Select the Id column in EF designer and open its Properties Grid (F4). Then set StoreGeneratedPattern to Identity, save your changes and try again.

3.; Try to update the model. Right-click the design surface of the EF diagram and choose Update Model from Database and follow the on-screen instructions.

Hope this helps, and if not please let me know.

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!
The Following User Says Thank You to Imar For This Useful Post:
marcin (April 13th, 2011)
 
Old April 13th, 2011, 05:06 AM
Registered User
 
Join Date: Apr 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Wow!!!!!!!!!!!!

Thanks for such fast answer. Solution number 3 worked. Now, i won't forget that i have to refresh ef every single time i do something with the tables.
You are the Man Imar!!!
 
Old April 13th, 2011, 05:10 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're welcome.

And yes, you need to refresh the model every time you make a change in the database. The model is saved in XML files (the .dbml file) and code files (.cs or .vb) and it's not automatically refreshed or recompiled (which is a good thing as it could otherwise break your code) when you change the database.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Try It Out Page 555 jlransford BOOK: Beginning ASP.NET 4 : in C# and VB 5 September 11th, 2010 04:02 PM
General question - Master Pages, Base pages, templates and OOP. flapjack BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 May 1st, 2010 09:33 AM
Master Pages, Content Pages and CSS carliviris Visual Studio 2005 0 January 8th, 2008 05:56 PM
Web pages constructing: I-mode(mobile) pages karib Dreamweaver (all versions) 3 June 6th, 2004 09:48 AM
has more pages Louisa VB.NET 2002/2003 Basics 0 May 25th, 2004 10:09 AM





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