Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get detail entity Id in AfterSave handler on a Master/Detail #4370

Closed
wchitirobho opened this issue Apr 2, 2019 · 4 comments
Closed

Comments

@wchitirobho
Copy link

Hi Guys,

I have a master/detail relation between an invoice(master) and a detail entity (detail). The CRUD work very well for both master and detail entities.

My issue, is that I need to use the detail entity Id after I have saved the master entity(invoice).

The master (Invoice) and detail both have autoIncrement Ids.

Here is a piece of my code in the Save handler of the master repository:
protected override void AfterSave()
{
base.AfterSave();
if (Row.OrderItems != null)
{
foreach (var item in Row.OrderItems)
{
var purchaseInvoiceItemId = item.PurchaseInvoiceItemId.Value;

.....
item.PurchaseInvoiceItemId.Value = null when creating the record, it only has a value when updating.

How can I get the detail entity Id when creating the creating the detail record? or how can I refresh to get the Id.

How to refresh detail record

@wchitirobho
Copy link
Author

managed.

@vinnaykulkarni
Copy link

Hi @wchitirobho can you please share what work around you followed
As we are also facing same issue

@reach2rv
Copy link

@wchitirobho and @vinaykulkarni89 can you guys please post your solution for this.

@minhhungit
Copy link
Contributor

I know we are using Discussion for questions but to avoid people keep asking on this thread I will post the solution here

My solution is quite simple I think, we will re-load child items where child.ParentId = Row.Id (master.ID)

protected override void AfterSave()
{
    base.AfterSave();

    var products = this.Connection.List<Entities.OrderProductRow>(new Criteria(Entities.OrderProductRow.Fields.OrderId) == (int)Row.Id);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants