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 September 24th, 2014, 07:14 PM
Registered User
 
Join Date: May 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Error in Ch. 14 Try It Out

I'm working on the try it out "Inserting and Deleting Data with the ListView Control". I think I've followed all of the instructions, but when I click "Insert" on the "Manage Photo Album" page, I get this error:

Unable to update the EntitySet 'Picture' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

Any one see this before or have an idea? I can go through the exercise again, but I'm hoping I just missed something.

Thanks
 
Old September 26th, 2014, 09:37 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,

Did you make the Id columns in the database an identity and primary key before you generated (or updated) the model?

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 September 26th, 2014, 09:51 PM
Registered User
 
Join Date: May 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I believe I did not have the ID column on PhotoAlbum as a key.

However, I can't remember or find how to generate or update the model.
 
Old September 27th, 2014, 09:16 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,

To set the identity and primary key, take a look at the exercise at page 423 and further.

To refresh the model after you changed the database, look at the exercise on page 498 and further.

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!
 
Old September 28th, 2014, 04:21 PM
Registered User
 
Join Date: May 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

That did help.

I refreshed the model as directed, then when I rebuilt the website, I got the following error:


Error 1 Error 3002: Problem in mapping fragments starting at line 210:Potential runtime violation of table Picture's keys (Picture.Id): Columns (Picture.Id) are mapped to EntitySet Pictures's properties (Pictures.Id) on the conceptual side but they do not form the EntitySet's key properties (Pictures.Description, Pictures.Id, Pictures.ImageUrl, Pictures.PhotoAlbumId, Pictures.ToolTip).
C:\BegASPNET\Site\App_Code\PlanetWrox.edmx 211 15 C:\BegASPNET\Site\


I searched in the .edmx file for ImageUrl and found this:
Code:
<EntityType Name="Picture">
          <Key>
            <PropertyRef Name="Id" />
            <PropertyRef Name="Description" />
            <PropertyRef Name="ToolTip" />
            <PropertyRef Name="ImageUrl" />
            <PropertyRef Name="PhotoAlbumId" />
          </Key>
          <Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Type="String" Name="Description" Nullable="false" MaxLength="300" FixedLength="true" Unicode="true" />
          <Property Type="String" Name="ToolTip" Nullable="false" MaxLength="50" FixedLength="true" Unicode="true" />
          <Property Type="String" Name="ImageUrl" Nullable="false" MaxLength="200" FixedLength="true" Unicode="true" />
          <Property Type="Int32" Name="PhotoAlbumId" Nullable="false" />
          <NavigationProperty Name="PhotoAlbum" Relationship="PlanetWroxModel.FK_Picture_PhotoAlbum" FromRole="Picture" ToRole="PhotoAlbum" />
        </EntityType>
I removed all but the "Id" line from the "Key" entry, rebuilt the web site, and everything works.

Thanks for your help!
 
Old September 29th, 2014, 06: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

Yep, that makes sense. When a table has no key define, EF assumes all columns in the table make up the (composite) primary key. It should have detected your change though when you refreshed the model, so I am not sure why you needed to manually edit the EDMX.

Anyway, glad it's working now.

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
Ch.14 .NETFramework error smileys6971 BOOK: Beginning ASP.NET 4 : in C# and VB 8 February 25th, 2013 02:06 PM
CH 14 A Simple EntityDataSource Application - Error! leeWozyWarren BOOK: Beginning ASP.NET 4 : in C# and VB 5 December 7th, 2011 02:28 PM
Ch 14: Try it Out p. 511 - error 'dependent property in a ReferentialConstraint' jayinatlanta BOOK: Beginning ASP.NET 4 : in C# and VB 2 November 6th, 2011 12:32 AM
Ch 14: Try it Out p. 510 - error 'PlanetWroxModel.Picture' is a 'type' jayinatlanta BOOK: Beginning ASP.NET 4 : in C# and VB 2 November 5th, 2011 09:50 AM
CH 14 - Link Error - Unresolved Razzy The Pug BOOK: Ivor Horton's Beginning Visual C++ 2005 2 March 18th, 2008 06:44 PM





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