I have a table with the main identifier key, this field is not an identification column. My migration for Entity Framework 6 -
CreateTable( "dbo.Action", c => new { ID = c.Int(nullable: false, identity: false), ActionName = c.String(maxLength: 50), }) .PrimaryKey(t => t.ID);
All this looks quite frank. Then I have a way to sow some data:
public static void Seed(this DbSet<Action> entitySet) { MainContext dbCtx = DataRepositoryBase<Action>.GetContext(entitySet) as MainContext; if (dbCtx != null) { entitySet.Add(new Action() { ID = 1, ActionName = "Test" }); } }
At this moment I get an error
"Cannot insert a NULL value in the column identifier ', table' dbo.Action '; the column does not allow zeros. INSERT fails. Stops"
As you can see, I explicitly provide a value for the ID column. My suspicion is that the Entity Framework expects the identifier to be an Identity column
Entity class is very simple.
[DataContract] public class Action { [DataMember] public int ID { get; set; } [DataMember] public string ActionName { get; set; } }
keitn source share