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

Vertical inheritance, Setting Base class Navigation property throw exception

6 Answers 86 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.
Benjamin
Top achievements
Rank 1
Benjamin asked on 29 Jan 2013, 05:16 PM

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

6 Answers, 1 is accepted

Sort by
0
Benjamin
Top achievements
Rank 1
answered on 30 Jan 2013, 07:28 PM
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.
0
Benjamin
Top achievements
Rank 1
answered on 30 Jan 2013, 08:17 PM
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
0
Benjamin
Top achievements
Rank 1
answered on 30 Jan 2013, 08:40 PM
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

0
Damyan Bogoev
Telerik team
answered on 01 Feb 2013, 02:34 PM
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.
0
Benjamin
Top achievements
Rank 1
answered on 03 Feb 2013, 07:18 PM
Hi Damyan,

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

Best regards
0
Damyan Bogoev
Telerik team
answered on 06 Feb 2013, 09:43 AM
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.
Tags
General Discussions
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Benjamin
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Share this question
or