This is a migrated thread and some comments may be shown as answers.

NoSuchObjectException with non nullable foreign keys

8 Answers 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Christoph
Top achievements
Rank 1
Christoph asked on 30 Mar 2011, 04:31 PM
Hello

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

Sort by
0
Zoran
Telerik team
answered on 04 Apr 2011, 05:02 PM
Hello Christoph,

 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Christoph
Top achievements
Rank 1
answered on 06 Apr 2011, 07:08 AM
Helllo Zoran

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
0
Zoran
Telerik team
answered on 11 Apr 2011, 05:55 PM
Hello Christoph,

 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Christoph
Top achievements
Rank 1
answered on 12 Apr 2011, 02:58 PM
Hello Zoran

Thank you for your answer, I think I will stick with the nullable attributes then.

Regards
0
Jack
Top achievements
Rank 1
answered on 25 Apr 2011, 09:52 PM
Is there any news?

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
0
Zoran
Telerik team
answered on 28 Apr 2011, 06:00 PM
Hello Christoph,

 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yijun
Top achievements
Rank 1
answered on 09 Apr 2013, 07:07 PM
It seems this issue is back with the latest version on OpenAccess 2013.1 219.
Can you please verify this.  I'm having this probrem with the latest version.

Regards,

Yijun

0
PetarP
Telerik team
answered on 12 Apr 2013, 03:35 PM
Hello 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.

All the best,
Petar
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
Tags
General Discussions
Asked by
Christoph
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Christoph
Top achievements
Rank 1
Jack
Top achievements
Rank 1
Yijun
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or