p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Error in Ch. 14 Try It Out (http://p2p.wrox.com/showthread.php?t=93621)

FrugalRacer September 24th, 2014 07:14 PM

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.


Imar September 26th, 2014 09:37 AM

Hi there,

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


FrugalRacer September 26th, 2014 09:51 PM

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.

Imar September 27th, 2014 09:16 AM

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,


FrugalRacer September 28th, 2014 04:21 PM

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:

<EntityType Name="Picture">
            <PropertyRef Name="Id" />
            <PropertyRef Name="Description" />
            <PropertyRef Name="ToolTip" />
            <PropertyRef Name="ImageUrl" />
            <PropertyRef Name="PhotoAlbumId" />
          <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" />

I removed all but the "Id" line from the "Key" entry, rebuilt the web site, and everything works.

Thanks for your help!

Imar September 29th, 2014 06:38 AM

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.



All times are GMT -4. The time now is 10:59 PM.

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