Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 24th, 2014, 08:14 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old September 26th, 2014, 10:37 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 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!
Reply With Quote
  #3 (permalink)  
Old September 26th, 2014, 10:51 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #4 (permalink)  
Old September 27th, 2014, 10:16 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 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!
Reply With Quote
  #5 (permalink)  
Old September 28th, 2014, 05:21 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!
Reply With Quote
  #6 (permalink)  
Old September 29th, 2014, 07:38 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01: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 10:50 AM
CH 14 - Link Error - Unresolved Razzy The Pug BOOK: Ivor Horton's Beginning Visual C++ 2005 2 March 18th, 2008 07:44 PM



All times are GMT -4. The time now is 10:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.