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 May 20th, 2013, 02:49 AM
Registered User
 
Join Date: May 2013
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default Beg Asp Net 4 in C# & VB pages 555-564

Hi -

I got this message on Chapter 15 exercise "Cannot insert explicit value for identity column in table 'Review' when IDENTITY_INSERT is set to OFF." If I tried to change the Identity Specification to NO - but, I got this message "Violation of PRIMARY KEY constraint 'PK_Table2'. Cannot insert duplicate key in object 'dbo.Review'. The statement has been terminated."

I tried also the following:

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.

All are to no avail.

Appreciate help

Jorgen
 
Old May 20th, 2013, 06: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,

You need to set (Is Identity) to all Id columns in the tables in the database. After you've modified the database, you need to recreate the EDMX model again. Delete all tables from the EF diagram (and confirm you want them deleted from the underlying model as well) and then add them again.

Worst case, you need to start with a new diagram. If you try that out, first remove the PlanetWroxEntities connection string from web.config to avoid issues with duplicate connection strings.

If all this still fails, there may be something in your code that tries to set the ID explicitly, In that case, post the code (markup and code behind) of the relevant pages here.

Hope this helps,

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:
jorgen423 (May 24th, 2013)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Exercise in Beg. asp.net for VB.net! mrfella71 BOOK: Beginning ASP.NET 1.0 1 October 23rd, 2005 12:06 PM
Beg. ASP.Net eCommerce with VB.Net - Chapter 5 James Hendrix All Other Wrox Books 0 October 22nd, 2003 10:45 PM





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