locked
How to implement "get latests changed items" with ADO.NET Data Services? RRS feed

  • Question

  • Hi

    Lets say I have a lists of entities (for example, a list of TODO items) that more than one user can change, delete from and add to at the same time.

    So to maintane a synchronized listed between all the clients, I want each client (AJAX based) to ask for changes every xx seconds. Since the list can get veeery long, I do not want to do a full request each time, but only ask for the changed items (items can be updated, deleted or new).

    Is it possible with ADO.NET Data Services? If so, how do I implement it, if I use Entity Framework on the server?

    I have considered using ASP.NETs cache to store change items in when a change operation is submitted to the data service, and have a custom web method that would return the latest changes since the specific clients last request (requests could be tracked through the clients ASP.NETs session object). However, I have no idea how to indicate the change state of the individual item (e.g. deleted or updated or inserted) in the resultset.

    A great solution would also make it possible for the client to ask for changes in many entities in the same roundtrip to the server.

    Any input will be much appreaciated.

    Best regards, Egil.
    Monday, April 6, 2009 11:01 AM

Answers

  • Here's an thought of what you can do:

    This works for a single entity: If there is an entity already in the client, and you want to know what changes has been made to this entity in the server, you can query the same entity again (under no tracking merge option so that you don't conflict with the existing one - remember to add If-None-Match header, so that the entity is returned only if there are any changes).

    Now there are 3 cases:

        1> If the status code is 304, it means there are no changes to the entity
        2> If the status code is 404, it means this entity no longer exists on the server, which means its deleted.
        3> If the status code is 200, it means the entity has been modified and the current result entity is the latest version.

    You can compare each field yourself at the client and show the differences to the user and ask user to do conflict resolution.

    There are some things which you won't be able to figure out like if the entity has been deleted and a new entity has been added with the same key. It might be tricky to find if the relation has been changed (you might have to get the related entities and just compare the keys to say if the relationship with the same object exists).

    Hope this helps.

    Thanks
    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, April 8, 2009 4:30 PM
    Moderator

All replies

  • Hi,

    Astoria can work with optimistic concurrency through etags. It will help you synchronize all of your clients to the same entity, this artcile talks about how it is done.

    However, keep in mind that e-tags are simply an "I have changed" token. It'll be up to each of the client to resolve conflicts if there are also pending local changes, and currently there is nothing on the service that will generate a list of history on an entity. For that, you will have to either do it through database's storeproc, or through change interceptors.

    Regards,

    PQ

    Peter Q.
    Monday, April 6, 2009 9:34 PM
    Answerer
  • Hi Peter

    I guess there is no obvious way to do this with ado.net ds - i.e. some way to say "give me what changed in the resultset since last request".

    If I want to avoid change tracking data in the database (e.g. tombstone rows for deleted entities) its going to be hard to indicate to the client whether an entity is deleted, updated, or added.
    Tuesday, April 7, 2009 9:02 AM
  • Hi,

    Unfortunately that is correct. Astoria does not provide history of entities, you'll have to implement your own. How complicated it is depends on the level of details you want. I suspect for the most part simply keep an entry that says "entity deleted by [user]" is enough, unless you want the ability to fully rollback changes.

    Regards,

    PQ
    Peter Q.
    Tuesday, April 7, 2009 6:16 PM
    Answerer
  • Here's an thought of what you can do:

    This works for a single entity: If there is an entity already in the client, and you want to know what changes has been made to this entity in the server, you can query the same entity again (under no tracking merge option so that you don't conflict with the existing one - remember to add If-None-Match header, so that the entity is returned only if there are any changes).

    Now there are 3 cases:

        1> If the status code is 304, it means there are no changes to the entity
        2> If the status code is 404, it means this entity no longer exists on the server, which means its deleted.
        3> If the status code is 200, it means the entity has been modified and the current result entity is the latest version.

    You can compare each field yourself at the client and show the differences to the user and ask user to do conflict resolution.

    There are some things which you won't be able to figure out like if the entity has been deleted and a new entity has been added with the same key. It might be tricky to find if the relation has been changed (you might have to get the related entities and just compare the keys to say if the relationship with the same object exists).

    Hope this helps.

    Thanks
    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, April 8, 2009 4:30 PM
    Moderator