Entity Framework 4 not respecting database constraints for numeric fields
Say, I have a table in the DB defined as follows
Table: Foo
PkId - int, primary, autoincrement Bar - int, allow null=false, no defaultNow when generating the EF model from the database the 'Bar' field is correctly defined as Nullable=false, Type=Int32.
Now when I do the following
var foo = new Foo();
context.AddToFoos(foo);
context.SaveChanges();
The row is inserted into the database and 'B开发者_开发问答ar' has a value of 0? I would have expected an exception because Bar hasn't been set. I realise that 0 isn't null but its also not a value that I've set.
Is this by design or have I misunderstood something?
It's not nullable and thus an int. The default of int is 0. So the DB is happy and the framework is fine as well.
精彩评论