Master detail relations
External references is the base element of master-detail references definition in XData. It describes link rules between related detail entities from master entities. XData support multi master and multi detail relation (many-to-many). And it's possible to define multiple relations between every two data objects.
External references is the declarations of possible master-detail relations between data objects. Each of external reference is describe master property (or column) to detail filter relation, used to filter detail collections data when master current object is set.
Tip
External references applied to manually attached detail data sources only.
External references definition is differs for static and dynamic methods of mapping.
Reference rules is defined at mapping level, and when detail object will be attached using GetChild method, that rules will be applied.
To fill child repository data in some unmapped array property (when the reference has type "one-to-many") can be used special overload of GetChild method. And when reference has type "one-to-one" can be used GetChild overload. That properties will be filled by child data automatically during data acquire when child repositories has been connected using that overloads of method.
var rep = dataScope.GetRepository<Invoice>();
var child = rep.GetChild(z => z.InvoiceSpec);
Warning
Data hierarchy can be acquired by that way has not limited deep level, but important keep in mind the price of that is performance. Use child repository data loading into unmapped properties when needed only!
To break master-detail reference call DetachChild method. When data scope or one of referenced repositories will be disposed - reference is beaked automatically.
Detail object reference filter value is set when SetCurrent extension method is called for master object.
if (newInvoice.Submit())
{
newInvoice.SetCurrent();
return true;
}
Master-detail linked repositories can be used for cascade delete operation over multiple related data objects:
newInvoice.SetDeleted(true);
newInvoice.Submit();
or cascade delete applied for filtered subset of repository objects and their detail objects:
invoices.Clear(x => x.DocStateCode == "REJECTED");