This is a follow up to this question
Entity Framework 4 not respecting database constraints for numeric fields
Is it possible to achieve the following
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 'Bar' has a value of 0?
What I would expect is an application level exception because Bar hasn't technically been set by the application. Its .Net default value does not automatically translate to a valid value for a particular database.
The behaviour should be similar to string columns in the DB. Strings are correctly handled because they have a null state and this translates well.
How is this normally achieved for numeric columns?