【问题标题】:Visual Studio 2010 + Entity Framework 4: UpdateException on SaveChangesVisual Studio 2010 + Entity Framework 4:SaveChanges 上的 UpdateException
【发布时间】:2011-06-29 18:34:51
【问题描述】:

经过大量研究并就 VS2010 SP1 未发布修补程序的测试与 Microsoft 联系(我以为我遇到了这个错误:http://connect.microsoft.com/VisualStudio/feedback/details/505178/storegeneratedpattern-property-in-ado-net-entity-model-designer-sets-cdsl-annotation-but-not-ssdl-attribute),我想我会与您分享。

本质上,我的实体模型设计器似乎运行良好,因为它添加 Identity 作为我的 ID 属性的 StoredGeneratedPattern 字段的正确值(在 edmx 文件的 SSDL 和 CSDL 区域中)但是当我调用 context.SaveChanges () 从我为测试 EF 设置而创建的一个简单应用程序中,我得到了一个 UpdateException,带有以下 InnerException(在 UpdateException 对象中的任何位置都可以找到唯一有意义的文本):

{"不支持修改主键列的属性 'StoreGeneratedPattern' 设置为 'Computed' 的表。改用 'Identity' 模式。键列:'Id'。表:'ConfigurationManagerServiceEntityDataModel.Store .ServiceConfigurationItems'。"}

然而,这根本不可能,因为在整个解决方案中都找不到 Computed。

我已经多次从模型中重新生成数据库,并在 SQL Server Management Studio 下检查了 SQL 以及生成的表结构和列属性,一切看起来都很好。

为了进一步参考,这里是异常似乎引用的特定模型对象 edmx 规范:

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>

该表的SQL生成如下:

-- 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

在这一点上,我不知道问题可能是什么。

任何帮助将不胜感激!

非常感谢。

【问题讨论】:

    标签: .net visual-studio-2010 entity-framework


    【解决方案1】:

    好吧,我从头开始重新做了一遍,问题似乎不再发生了。

    感谢所有花时间阅读本文的人!

    【讨论】:

      猜你喜欢
      • 2011-07-23
      • 1970-01-01
      • 2011-02-08
      • 2023-03-18
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多