Vertical inheritance, Setting Base class Navigation property throw exception

7 posts, 0 answers
  1. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 29 Jan 2013 Link to this post

    Hello,
    I use EF for several years and I'm testing Open Access.

    I Have the following model :

    Address
    Identifier
    Address
    City
    ...

    BusinessRecord (base class for Invoice)
    Identifier
    IdentifierAddress
    Reference
    ...

    Invoice (Sub class)
    PayementDate
    ...

    Invoice have the Address navigation property and IdentifierAddress property inherit from BusinessRecord.
    When I Set the IdentifierAddress, no problem.
    When I Set the Address, I get the following exception :

    No row for BusinessManager2012.DAL.Address ('Address') GenericOID@5d464c86 Address Identifier=0

    The problem hapen only when adding Invoice, not when editing a loaded one.

    Thank you

  2. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 30 Jan 2013 Link to this post

    Hello,

    I have found that if I add the Invoice object in my context via the context.Add method after setting the Address Navigation property I don't get this error. This solution doesn't suit me because I need to track if the object has changed via the context.HasChanges property so I realy need to add the object in the context before setting the Address in the model.

    For information, I use SQL Server 2012 express and Database-first model.
  3. DevCraft banner
  4. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 30 Jan 2013 Link to this post

    Hello,

     Just found this thread : nosuchobjectexception with non nullable foreign keys

    I know it's a old one and I don't think it's the same bug but I'm in the same case.
    I tried to set the IdentifierAddress to nullable in DB and now it works without problem.
    It doesn't suit me because I want this field to be non nullable.

    Thank you
  5. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 30 Jan 2013 Link to this post

    I have found a solution, 

    I set the IdentifierAddress not null in DB.
    I set the nullable property of the IdentifierAddress int the model designer to true.

    This is working fine but why does I have to do this ? Does OpenAccess could set the FK property to nullable in the model by default or avoinding the exception when the FK property is not nullable ? I have a lot of non nullable FK property and if I have to change this property for all my associations, this is going to upset me...

    yes, I'm Lazy ! :)

    Thank you

  6. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 01 Feb 2013 Link to this post

    Hi Benjamin,

     
    I am glad to see that you have managed to resolve the issue.

    We will investigate the cause for the issue and will provide you with a solution to the problem.

    Kind regards,
    Damyan Bogoev
    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
  7. Benjamin
    Benjamin avatar
    24 posts
    Member since:
    Dec 2012

    Posted 03 Feb 2013 Link to this post

    Hi Damyan,

    Thank you for your response. Keep me up to date when you'll found the solution.

    Best regards
  8. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 06 Feb 2013 Link to this post

    Hi Benjamin,

    You need to mark the association ends as managed in order to avoid the error:

    - Select the association form the Visual Designer;
    - Press F4 to open the Properties Grid;
    - Mark both the source and target properties as managed (see the screenshot attached);
    - Save the diagram;

    You could find the sample application, used for testing on our side, attached to my answer. Additional helpful information can be found here and here.


    Greetings,
    Damyan Bogoev
    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Back to Top
DevCraft banner