Hi All,
I'm building a data entry/maintenance screen. My database tables are as such:
Company (nullable FK to Address)
Address
Contact (nullable FK to Company)
they are mapped on the Entities as
Company with Company.Address and Company.Contacts
Address
Contacts
The foreign keys to both of those tables are nullable. This is to represent the fact that a user does not have to enter all of the information at one time. This, of course presents a problem when binding the Company object to controls on the form.
textBox1.DataBindings.Add("Text", companyBindingSource, "CompanyName");
textBox2.DataBindings.Add("Text", companyBindingSource, "Address.AddressLine1");
Address will often be null.
So, what are my options here? I could remove the nullability on the FKs, so there will always be an Address. I don't like the idea of modifying my schema to meet the needs of the UI though.
I could create a custom property on Company like AddressForDataBinding and provide an instance for databinding.
I could also explicitly instantiate an Address object on retrieving a Company if an Address has not been defined, but that will mean it will get persisted even if nothing is entered, which is just like removing the non-nullability, but at the app layer instead of the db layer.
I could also (and probably will) map Address fields to the Company entity. As in:
Company.AddressLine1 <-- Company.Address.AddressLine1
Not sure about contacts yet.
Interested in thoughts and opinions.
Steve.