Otis wrote:
EmployeeId is an int.
I'm not sure what you're doing, Dennis, but setting a field's value to the default value on a new entity simply works and makes the entity's field changed and will thus be saved.
Databinding a textbox to EmployeeId will thus also work, when I set it to 0.
How exactly are you setting the values ?
Okay, what's happening is about this. I'm renaming the entities to something hopefully more understandable.
We have a table called "Order" and a table "OrderLines" in a 1:n relationship. On our WinForm, we're showing Order on the form and OrderLines in a list. We have a button to add a new orderline. When pressed, we instantiate a new orderline and do _order.OrderLines.Add(myOrderline);
Than myOrderline shows up in the listbox that shows all orderlines, belonging to this order. We manually select the orderline from the listbox. Than the changed event of the listbox is executed.
What happens next is that we set the SelectedItem from the listbox to a databindingsource. The selected orderline immediatly shows up in some extra textboxes. SURPRISE! All int fields have value 0!!!
Now we do nothing, and hit save! When looking into the order.orderlines, we see that one object IsNew and IsDirty. However, the properties with value 0 are NOT saved. And because those columns are "Allow Nulls = false" we get a nice little exception on the winform
When we're looking at the SQL Profiler it's also noticed that the columns with those 0 values aren't included in the update insert query.
ps. In table OrderLines we have 4 float columns and two foreign key columns. The foreign keys are included in the insert into statement.
edit : changed update into insert, mistype