Map a column to be IDENTITY in db with EF4 Code-Only
Posted
by Tomas Lycken
on Stack Overflow
See other posts from Stack Overflow
or by Tomas Lycken
Published on 2010-04-08T20:19:58Z
Indexed on
2010/04/08
20:23 UTC
Read the original article
Hit count: 581
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...
© Stack Overflow or respective owner