1

I am trying something with EF 4.1 that should be relatively easy. I have a class like this

class Entity 
{
   public int Id {get;set;}
   public string Name {get;set;}
}

The Id property should be the primary key in the DB and this all works. But when I insert new entities with given IDs EF4.1 ignores the ID and creates a new one. So I would like something like identity_insert?

Greeting, Martijn

Gluip
  • 2,917
  • 4
  • 37
  • 46
  • 1
    Does your EDM show the Id column as being the primary key? UPDATE: Sorry..just realized you're doing code-first. Have you tried setting a [key] attribute on your Id to indicate to EF that Id is the primary key? – Anthony Nov 03 '11 at 18:14

1 Answers1

0

I'm tempted to closed as a duplicate of this question, but it's not clear from the text if you want to have a property that is always created by your code, or just sometimes (as it is in that question)

Community
  • 1
  • 1
Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154