0

In EF4 I have the following table

CREATE TABLE [dbo].[Things](
    Id] [uniqueidentifier] NOT NULL,
    [Text] [nvarchar](2048) NULL,
 CONSTRAINT [PK_AdjustmentMarker] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

In the EDMX the StoreGeneratedPattern is set to Identity:

<Property Name="Id" Type="uniqueidentifier" Nullable="false" StoreGeneratedPattern="Identity" />

People can add comments on an anonymous environment (real data, but faked customer names, etc.). We export the comments on the anonymous environment and import them on the production environment and need to have the original keys. But when adding the comments using EF (AddObject) and after calling SaveChanges EF recalculated the Id and inserts the comment with the new Id.

Am I gettings something wrong? I thought StoreGeneratedPatter = Identity will do the trick?

Source: "Set the StoreGeneratedPattern attribute to "Identity" in your SSDL for the autoincrement field. It should help. " (Autonumber with Entity Framework)

MiGro
  • 471
  • 1
  • 4
  • 17
  • 1
    For the `StoreGeneratedPattern` attribute, you can have a look at this: https://stackoverflow.com/a/4532506/4636715 – vahdet Jul 24 '18 at 13:35
  • I just edited above. But does this mean that the source stackoverflow I linked is a wrong answer? – MiGro Jul 24 '18 at 13:37

0 Answers0