POCO Change Tracking Strategies

I have an N-level application where POCOs are populated by the server-side Entity Framework and passed to my client applications. Clients make changes to POCOs or add new POCOs and then send them back to the server, which will be stored in the database.

If I use pure POCO, i.e. not proxies, not objects of self-control, what are some common approaches that people take to solve the problem of tracking changes? If your service receives a collection of POCOs, how does it know what to do Add, Update or Delete using the Entity Framework?

+6
source share
1 answer

Entity Framework does not have good built-in support for such disabled scripts. I know three common options:

  • Use GraphDiff , an open source library

    <strong> Benefits

    • No need to write client-side change tracking code.
    • General template for updating graphs of disconnected objects in the database
    • Not much server side code


    disadvantages

    • A database must be queried and entities must be loaded to determine whether to add, update or delete an object.
    • Third-party library dependency in addition to EF core libraries


  • Update object graphs manually on the server side ( Example )

    <strong> Benefits

    • No need to write client-side change tracking code.
    • No dependency on a third-party library in addition to the main EF libraries


    disadvantages

    • A database must be queried and entities must be loaded to determine whether to add, update or delete an object.
    • There is no common template, i.e. most upgrade scenarios require separate code
    • Lots of server side code


  • Add the properties of entity states to your objects and manually track changes on the client side, setting the appropriate states (I have no example for this approach, I believe Julia Lerman uses and recommends it)

    <strong> Benefits

    • You do not need to query the database to determine whether to add, update, or delete an object.
    • No dependency on a third-party library in addition to the main EF libraries
    • (Maybe?) A generic server-side template for translating monitored states into entity states of attached objects.


    disadvantages

    • Change tracking code for client-side entries
    • There is no common template on the client side, that is, most change tracking scripts (and client types / user interface technologies) require an individual code
+6
source

Source: https://habr.com/ru/post/954813/


All Articles