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
private
int
Countryid;
public
virtual
int
CountryId
{
get
{
return
this
.Countryid;
}
set
{
this
.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?
Thank you
8 Answers, 1 is accepted
This is a known issue on our side and it is a bug that we have already fixed. We will release an internal build by the end of this week or early next week which will contain the fix of this bug.
Best wishes,Zoran
the Telerik team
Thank you for your answer. Will the "internal" build be available for download?
To solve the problem, I modified the code generation templates (*.tt files) so all the generated attributes become nullable (int becomes int? etc.)
It seems to work fine but I am still interested to know if it is possible that non nullable fields do not obtain a default value (0 for int, DateTime.Min for DateTime) when we instanciate a new Entity. Or at least that the default value do not appear in the databound control.
Regards
Yes the internal build will be available for download as soon as tomorrow. The default values of non-nullable fields can not be changed as this behavior is dictated by the .NET Framework for all value-types objects e.g. 0 for int, DateTime.Min for DateTime, 0.0 for double etc.
Kind regards,Zoran
the Telerik team
Thank you for your answer, I think I will stick with the nullable attributes then.
Regards
I'm evaluating OpenAccess for our systems migrations and just hit the same problem at the very beginning of testing.
It's 25th Apr and I can't see any internal build to check, can you confirm the date of the fix?
TIA
Jack
The version of the internal build is 2011.1.411 and it was released on the 11th of April. Are you having the issue with that version installed? If this is true than the cause of the problem may be of another nature as we do have a fix in that build. However if you still have the same issue, I believe it would be the best if you could send us your testing solution in a support thread so we can debug it locally and we will make sure that we provide you with a decent solution as soon as possible.
Greetings,Zoran
the Telerik team
Can you please verify this. I'm having this probrem with the latest version.
Regards,
Yijun
Since our tests are passing we don't believe its the same bug that has resurfaced but rather another one that is ultimately resulting in the same exception.
I suggest we continue the investigation on the matter in the support thread you have already raised.
Petar
the Telerik team