Base solution for your next web application
Open Closed

How to get the ID of a sub entity after saving #4622


User avatar
0
[email protected] created

When I insert a record with sub entity using the EF repository, I am getting the correct ID back in the parent record but negative ID for the child records!

I read about it online, they [https://stackoverflow.com/questions/5212751/how-can-i-get-id-of-inserted-entity-in-entity-framework]) I should call Save context in order to get the ID, and there's no such an option in the repository.

Any idea?


1 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Inject IUnitOfWorkManager and do:

    _unitOfWorkManager.Current.SaveChanges();