尽管StoreGeneratedPattern在SSDL中设置为Identity,但EF 4.1仍尝试在标识列中插入值

时间:2012-07-23 18:24:53

标签: entity-framework-4.1 poco identity-column

我在SQL Server 2008中有一个名为ScanMasters的表,它有一个名为PresentationAuditId的列作为主键。此列也是外键。该表还有一个名为ScanPartId的标识列。我正在使用Entity Framework 4.1根据我的数据库生成POCO。 EF SSDL以这种方式表示实体:

<EntityType Name="ScanMasters">
  <Key>
    <PropertyRef Name="PresentationAuditId" />
  </Key>
  <Property Name="ScanPartId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
  <Property Name="RackNum" Type="int" />
  <Property Name="LoadDatetime" Type="datetime" />
  <Property Name="PresentationAuditId" Type="bigint" Nullable="false" />
  <Property Name="Item" Type="varchar" MaxLength="31" />
</EntityType>

当我为这个实体添加新数据并执行SaveChanges()时,我收到以下错误:

当IDENTITY_INSERT设置为OFF时,无法在表'ScanMasters'中为标识列插入显式值。

我们可以在EF 4.1中将非主键列作为标识列吗?我怎么能这样做呢?

0 个答案:

没有答案
相关问题