Base solution for your next web application
Open Closed

Insert or Update disconnected complex object graph #122


User avatar
0
vitor lacerda created

Hi,

I need to insert or update a disconnected complex object graph.

I'm using angularjs / EF6 and use a IObjectState (interface) to define Added, Modified, Deleted and Unchanged states.

I want to define my Entities with ObjectState Interface and call a method InsertOrUpdateGraph on a Repository.

I cant extend IRepository<TEntity,TPrimaryKey> because a can access DBContext to attach object and change EntityState based on ObjectState.

Can you implement this pattern or explain how can i do this without change abp source code?

Sample implementation <a class="postlink" href="https://genericunitofworkandrepositories.codeplex.com/wikipage?title=Inserting%20a%20Complex%20Object%20Graph&referringTitle=Documentation">https://genericunitofworkandrepositorie ... umentation</a>

Thanks for your great work!

Vitor Lacerda


5 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    You can extend your base repository by adding methods (see <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/EntityFramework-Integration#DocAppBaseRepo">http://www.aspnetboilerplate.com/Pages/ ... ppBaseRepo</a>). You can access to DbContext in a repository using Context property. Do you want to access to DbContext from application layer? I think it's not true, but possible if you reference Abp.EntityFramework package from your app layer.

  • User Avatar
    0
    g.adolph created

    Great question,

    Hikalkan you don't answered about save a Complex Graph or Hierarquical Graph.

    As i know the EfRepositoryBaseOfTEntityAndTPrimaryKey handle only with main Entity.

    If i want update association entites( complex Graph), how can i do?

    If i have a disconnected object the only way your offer is comparing Id.

    What if EfRepositoryBaseOfTEntityAndTPrimaryKey could handle with complex Graph using ObjectState, what your opinion about this?

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I mean that you can extend repository to add such a method. When I check the link, I see the repository implementation: <a class="postlink" href="https://genericunitofworkandrepositories.codeplex.com/SourceControl/latest#main/Source/Repository.Pattern.Ef6/Repository.cs">https://genericunitofworkandrepositorie ... ository.cs</a> It does not seem too complicated. I think you can implement it in a base repository class and use for all repositories. I will also check it deeply to see if we should add such a method to the generic repository. Follow the issue: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/506">https://github.com/aspnetboilerplate/as ... issues/506</a>

    Beside that, I don't use such a complex object that is changed on client. What type of application are you building? A web app? If it's a web app, ABP suggest to use DTOs instead of sending Entities to UI.

  • User Avatar
    0
    vitor lacerda created

    My app is an Angularjs SPA and i use DTO but i need to update ViewModel like "sales order" with "sales order itens", "Customer" with "Address" (One to Many) and i need to know which Childs Objects ("Address" , "sales order itens") was added, modified, deleted and unchanged and sync with Entity (EntityState).

  • User Avatar
    0
    hikalkan created
    Support Team

    OK, please implement it yourself as I described above for now, then we consider to add to base repository. Also, it's appreciated if you share experience and codes here.

    Thanks.