Visual Studio 2010 + Entity Framework 4: UpdateException on SaveChanges

After much research and contacting Microsoft regarding the testing of an unreleased hotfix for VS2010 SP1 (I thought I had hit this bug: http://connect.microsoft.com/VisualStudio/feedback/details/505178/storegeneratedpattern-property-in-ado-net-entity-model-designer-sets-cdsl-annotation-but-not-ssdl-attribute), I thought I would share this with you.

In essence, my Entity Model Designer appears to work well, as it adds Identity as the right value for the StoredGeneratedPattern field of my ID property (in both SSDL and CSDL regions of the edmx file) however when I invoke context.SaveChanges() from a simple application I have created to test the EF setup, I get an UpdateException, with the following InnerException (the only meaningful text to be found anywhere in the UpdateException object):

{"Modifications to tables where a primary key column has property 'StoreGeneratedPattern' set to 'Computed' are not supported. Use 'Identity' pattern instead. Key column: 'Id'. Table: 'ConfigurationManagerServiceEntityDataModel.Store.ServiceConfigurationItems'."}

This, however, is simply impossible, as Computed is nowhere to be found in the entire solution.

I have re-generated the database from the model numerous times and examined both the SQL as well as the resulting table structure and column properties under SQL Server Management Studio and everything looks just fine.

For further reference, here is the specific model object edmx specification that the exception appears to be referencing:

SSDL:

<EntityType Name="ServiceConfigurationItems">
    <Key>
      <PropertyRef Name="Id" />
    </Key>
    <Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
    <Property Name="ItemName" Type="nvarchar(max)" Nullable="false" />
    <Property Name="ParentCategoryName" Type="nvarchar(max)" Nullable="false" />
    <Property Name="VicimusService_Id" Type="int" Nullable="false" />
</EntityType>

CSDL:

<EntityType Name="ServiceConfigurationItem">
          <Key>
            <PropertyRef Name="Id" />
          </Key>
          <Property Type="Int32" Name="Id" Nullable="false" a:StoreGeneratedPattern="Identity" xmlns:a="http://schemas.microsoft.com/ado/2009/02/edm/annotation" />
          <Property Type="String" Name="ItemName" Nullable="false" />
          <Property Type="String" Name="ParentCategoryName" Nullable="false" />
          <NavigationProperty Name="VicimusService" Relationship="ConfigurationManagerServiceEntityDataModel.VicimusServiceConfigurationItem" FromRole="ConfigurationItem" ToRole="VicimusService" />
          <NavigationProperty Name="ConfigurationItemDetails" Relationship="ConfigurationManagerServiceEntityDataModel.ServiceConfigurationItemConfigurationItemDetails" FromRole="ServiceConfigurationItem" ToRole="ConfigurationItemDetails" />
        </EntityType>

And the SQL for this table is generated as follows:

-- Creating table 'ServiceConfigurationItems'
CREATE TABLE [dbo].[ServiceConfigurationItems] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ItemName] nvarchar(max)  NOT NULL,
    [ParentCategoryName] nvarchar(max)  NOT NULL,
    [VicimusService_Id] int  NOT NULL
);
GO

At this point, I have no idea what the problem may be.

Any help would be tremendously appreciated!

Many thanks in advance.

Upvotes: 0

Views: 542

Answers (1)

Well, I did it all again from scratch and the issue no longer appears to be happening.

Thanks to all of you that took the time to read through this!

Upvotes: 0

Related Questions