0

Using Delphi XE5 and Devart EntityDAC ORM.

I have two entities linked one-to-one:

Project( Id, Name, ... ) and ProjectSchedule ( Id, ProjectId, ... );

In general schedule's fields may be easily inluded in Project table but I separated it for further possible needs. So, in Entity Developer I linked them as one-to-one relationship with Cascade=True and Delete_Rule=Cascade. Ok. But when I try

project.DeleteAndSave( True );

I get and DB exception: FK violated. Child record found.

But if I change relationship to one-to-many the same works fine. But in this case access to schedule looks like

project.ProjectShedules.First

which is really terrible.

How to cascade delete an one-to-one related entities?

AvoiDFaTE
  • 97
  • 9
  • The one to one links most of the cases exists just in the analysis phase and merged one into the another one in the later design phases. Maybe you could consider it as well. – SOLID Developper Oct 02 '18 at 07:27
  • Maybe you use a bidirectional relation in db level (never do that, use owner and owned sides) and use constraints to check data validity. One to many always unidirectional so works fine. – SOLID Developper Oct 02 '18 at 07:31
  • @Bitman, thx for reply, but there is actually one constraint like shown in question. At DB level it's typical one-to-many relation which possibly will be used in future. However in my model I want to access schedule object like project.ProjectSchedule as clearly should be designed in ORM. But I can't. So I think I do something wrong. – AvoiDFaTE Oct 02 '18 at 09:01

0 Answers0