2

I have a table called ScanMasters in SQL Server 2008 which has a column called PresentationAuditId as the primary key. This column is also a foreign key. The table also has an identity column called ScanPartId. I am using Entity Framework 4.1 to generate POCOs based on my database. The EF SSDL represents the entity in this manner:

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

When I add new data for this entity and do SaveChanges(), I am getting the following error:

Cannot insert explicit value for identity column in table 'ScanMasters' when IDENTITY_INSERT is set to OFF.

Can we have a non-primary key column as an identity column in EF 4.1? How can I go about this?

4

0 回答 0