Map a column to be IDENTITY in db with EF4 Code-Only
- by Tomas Lycken
Although I have marked my ID column with .Identity(), the generated database schema doesn't have IDENTITY set to true, which gives me problems when I'm adding records. If I manually edit the database schema (in SQL Management Studio) to have the Id column marked IDENTITY, everything works as I want it - I just can't make EF do that by itself.
This is my complete mapping:
public class EntryConfiguration : EntityConfiguration<Entry>
{
public EntryConfiguration()
{
Property(e => e.Id).IsIdentity();
Property(e => e.Amount);
Property(e => e.Description).IsRequired();
Property(e => e.TransactionDate);
Relationship(e => (ICollection<Tag>)e.Tags).FromProperty(t => t.Entries);
}
}
As I'm using EF to build and re-build the database for integration testing, I really need this to be done automatically...