Hi,
I have a typical master-detail case. Here is the structure:
Entity: Master
Fields:
Id (PK),
Caption,
CurrentDetailId (FK,Nullable)
Navigators:
CurrentDetail based on M : (0-1) the relation for CurrentDetailId -> Detail.Id
Details based on the 1:m relation for Id -> Detail.MasterId
Entity: Detail
Fields:
Id (PK),
Caption,
MasterId (FK,Not Null)
Navigators:
None
I want to save master with details and set Master.CurrentDetail to one of the new details that are going to be created:
var master = new MasterEntity {Caption= "m1"};
master.Details.Add(new DetailEntity { Caption = "d1" });
master.Details.Add(new DetailEntity { Caption = "d2" });
master.Details.Add(new DetailEntity { Caption = "d3" });
master.CurrentDetail = master.Details.Last();
adapter.SaveEntity(master);
When I save it, it throws exception. I understand that it is a cyclic reference to the detail that is not created yet when we save the master, but anyway it is still possible to save such structure into the database.
As for me it makes sense to support this case, you have all dependencies in place. And you are building the correct order of saving the graph, but you are not covering this (I'd say typical) scenario.
- Is there any problems with it?
- Is it going to be supported at all?
It is a nightmare to handle such cases(do not forget about it), but also even bigger problem if I use a UnitOfWork - I can not add it twice, so I need to use update entities derectly or smth like this.
- Any suggestions, commets?
Thanks,
Anton