0 Replies - 2928 Views - Last Post: 31 January 2012 - 03:48 AM

#1 kstr  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 60
  • Joined: 19-October 09

EF: Create objects with a specific id

Posted 31 January 2012 - 03:48 AM

Hi all,

I am working on a project where i need to convert an old database so the data can be used in my new solution.
For the new solution i am using Entity framework.

I want to make sure that the id's of the objects remains the same as in the old database, so i want to create an object with a specific id. After the conversion, the id field must auto-increment (as usual)

I know i can use a sql statement like this:
SET IDENTITY_INSERT cao_dev.CAO.CAO_unicornSet ON


But i still cannot set the id of the created object...

I did not find anything on the web so i am quite desperate...

Here is a part of my code:
 unicorn.Id = id 'from db
 unicorn.name = "Unicorn 1"
 db.unicornSet.AddObject(unicorn)
 db.SaveChanges()



Any ideas?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1