Entity keys: adding your own ids

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Coldstart
Posts: 2
Joined: Thu 04 Jun 2009 08:29

Entity keys: adding your own ids

Post by Coldstart » Thu 04 Jun 2009 09:35

Hi,

I ran into the following problem: I have this legacy database with a table Foo. This table contains a technical Primary key ID.

In the past we called a stored procedure to get a range of ids from a sequence, assigned them and then persisted the rows in one batch insert.

Is there a way to override the key generation of a certain entity? So I can inject my own key generation algoritm?

Or is there a way change the entity keys before an insert takes place?

Thanks.

Best regards,

S

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 05 Jun 2009 08:13

I advise you either to make a trigger on inserting the row into the table and set the StoreGeneratedPattern property to Identity
or, as an alternative, to write a method calling the stored procedure returning the ids and then populate these ids
in the code before saving the entities.
As for your questions, there is no way to override the key generation, or the way to change the assigned Entity Key.

Coldstart
Posts: 2
Joined: Thu 04 Jun 2009 08:29

Thanks

Post by Coldstart » Fri 05 Jun 2009 09:10

Thanks for the advise, for now I implemented the second solution.

Greetings,

S

Post Reply