I am developping a wpf application using OpenAccess. I am a beginner with OpenAccess.
I generated an Entity named 'Customer'. The customer has a non nullable foreign key 'CountryId' towards the Table 'Country'
Country Ids start at 1.
I have a dialog where I try to create a new Customer.
By loading the dialog I create a new instance of Customer :
Customer m_customer = new Customer();
this.DataContext = m_customer;
The Country is selected with a combobox (Value = CountryId, Displaymember = CountryName)
The SelectedValue of the combobox is bound (with databinding) to m_customer.CountryId.
When I try to change the value in the combobox, I get a NoSuchObjectException in Customer.generated.cs
.Countryid = value; <= Exception
In fact when I initialize the Customer object, the CountryId is set to 0, the default value for an int.
Then when the CountryId is updated, the exception comes because not Country with Id 0 exists.
I would not like to set a default value for the country, I expect the value to be null or "not set", as long as the user did not make a choice. How could I resolve this problem? Am I missing something obvious?