Is the Entity Framework aware of identity columns?
I am using SQL Server 2005 Express Edition and have several tables where the primary key is an identity column. w
In C# you can do something like this to make it aware:
In your FooConfiguration.cs : EntityTypeConfiguration
:
this.Property(x => x.foo).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Then to use it, just be sure to insert the item into the context and call context.SaveChanges()
before using x.foo
to get the updated auto-incremented value. Otherwise x.foo
will just be 0 or null.