NoSuchObjectException with non nullable foreign keys

9 posts, 0 answers
  1. Christoph
    Christoph avatar
    8 posts
    Member since:
    Mar 2011

    Posted 30 Mar 2011 Link to this post

    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
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 04 Apr 2011 Link to this post

    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
  3. DevCraft banner
  4. Christoph
    Christoph avatar
    8 posts
    Member since:
    Mar 2011

    Posted 06 Apr 2011 Link to this post

    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
  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 11 Apr 2011 Link to this post

    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
  6. Christoph
    Christoph avatar
    8 posts
    Member since:
    Mar 2011

    Posted 12 Apr 2011 Link to this post

    Hello Zoran

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

    Regards
  7. Jack
    Jack avatar
    1 posts
    Member since:
    Apr 2011

    Posted 25 Apr 2011 Link to this post

    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
  8. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 28 Apr 2011 Link to this post

    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
  9. Yijun
    Yijun avatar
    3 posts
    Member since:
    Feb 2013

    Posted 09 Apr 2013 Link to this post

    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

  10. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 12 Apr 2013 Link to this post

    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 >>
Back to Top
DevCraft banner