0

I created a simple code first entity for learn purpose. Does EF6 automatically select the property to auto-increment? Because I found that it appears to be doing this. Does it automatically select the primary key too?

My search on this question yielded answers to questions of how to switch the identity property using "Data Annotations" Source but that doesn't exactly answer my question.

klau
  • 67
  • 1
  • 9

1 Answers1

0

Does EF6 automatically select the property to auto-increment?

What you are describing is an Identity column (auto increments) which is also a primary key.

So let's visit the documentation:

Code First Data Annotations

Entity Framework relies on every entity having a key value that is used for entity tracking. One convention of Code First is implicit key properties; Code First will look for a property named “Id”, or a combination of class name and “Id”, such as “BlogId”. This property will map to a primary key column in the database.

Note : the key will also be defined as Identity by default

There is a lot more to this and various ways to configure fields and tables, so I recommend reading the documentation thoroughly.

halfer
  • 19,824
  • 17
  • 99
  • 186
TheGeneral
  • 79,002
  • 9
  • 103
  • 141