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
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.
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
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
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.
Damyan Bogoev
the Telerik team
Thank you for your response. Keep me up to date when you'll found the solution.
Best regards
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.
Damyan Bogoev
the Telerik team