I use EF CTP 4. I have a simple console application (for testing) that uses EF to insert some data into an SQL database.
I ran into a problem when inserting an element
using(var context = GetContext()) { BOB b = new BOB(); b.Id = 1; context.Bobs.Add(b); context.SaveChanges(); }
It throws an error: {"Cannot insert a NULL value in the Identifier column, table" TestDB.dbo.BOB "; the column does not allow nulls. INSERT does not work. \ R \ nApplication is complete." }
In the table there is only 1 field Id int NOT NULL, which is the primary key, and not automatically increasing identifier.
When creating a DataContext, I have this configuration, which yes works.
protected override void OnModelCreating(ModelBuilder builder) { builder.Entity<BOB>().HasKey(b => b.Id); builder.Entity<BOB>().MapSingleType().ToTable("BOB"); }
I also pre-populated this table, and then through the debugger I was able to view the clock loading this BOB object ... so I'm actually a dead end, since in order to load my BOB, everything is correct ... however, when inserting a new one crash ...
c # entity-framework ctp4
Secret Squirrel Dec 14 '10 at 21:26 2010-12-14 21:26
source share