Caching and LLBLGen Pro

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 16-May-2006 08:48:57   

Hi,

would it be possible to work with the following scenario in LLBLGen?

* Lets say I would like to load a very big customers collection with their photos via a Web Service from a service layer.
* Now I change some of the customers on the client and save the changes. The client should only send back the changed customers via the WebService to the service layer (which saves them to the DB).
* Now I would like to refresh the customer collection on the client but I would like the service layer to only send changed customers (updated, deleted, inserted) back and not all the customers again (to save bandwidth).

Has anybody done something similar with LLBLGen and if yes how did you do it simple_smile ?

Thanks a lot Patrick

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-May-2006 15:19:15   

There are no problems with the first 2 points.

Now for the third point:

  • Now I would like to refresh the customer collection on the client but I would like the service layer to only send changed customers (updated, deleted, inserted) back and not all the customers again (to save bandwidth).

I think you may need an extra field in the table let's call it "LastModifiedDate", that gets updated with GetDate() or sysdate whenever an entity is modified.

So when you first fetch the collection of entities you can easily get the maximum LastModifiedDate within those entities let's call it MaxFetchedModifiedDate.

You should use it again to filter your next Fetch, to select entities where LastModifiedDate > MaxFetchedModifiedDate.

This will get you the newly updated entities.

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 17-May-2006 01:08:46   

Walaa wrote:

There are no problems with the first 2 points.

You mean I would have to loop through the Customer collection to filter out all the dirty entities then create a new ChangedCustomer collection add all of the dirty entities to it and send this one back to the server to be saved?

Walaa wrote:

I think you may need an extra field in the table let's call it "LastModifiedDate", that gets updated with GetDate() or sysdate whenever an entity is modified.

So when you first fetch the collection of entities you can easily get the maximum LastModifiedDate within those entities let's call it MaxFetchedModifiedDate.

You should use it again to filter your next Fetch, to select entities where LastModifiedDate > MaxFetchedModifiedDate.

This will get you the newly updated entities.

The only thing here is that the deleted entities ones would be missing. Would the only way to solve this be to make a boolean column IsDeleted in the table and then transfer the deleted entities as well back to the client where they could be synced?

Would I then send this ChangedCustomer collection back to the client? Then while looping through the ChangedCustomerEntity I would look for the CustomerEntity with the same primary key in the Customer collection and replace the Entity there with the changed one?

Thanks for your help Patrick

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-May-2006 07:55:17   

You mean I would have to loop through the Customer collection to filter out all the dirty entities

you may use EntityCollection.DirtyEntities property (Returns a readonly collection of entities which are flagged as dirty)

The only thing here is that the deleted entities ones would be missing. Would the only way to solve this be to make a boolean column IsDeleted in the table and then transfer the deleted entities as well back to the client where they could be synced?

Yes that's how I may do it.

Would I then send this ChangedCustomer collection back to the client? Then while looping through the ChangedCustomerEntity I would look for the CustomerEntity with the same primary key in the Customer collection and replace the Entity there with the changed one?

Exactly, OR you might add the entities from the OLD collection to the NEW one (not the other way), and with the help of EntityCollection.DoNotPerformAddIfPresent property (default = true), old entities that have a modified version in the new EntityCollection won't get copied.

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 17-May-2006 08:11:22   

Thanks for all your feedback already simple_smile

Walaa wrote:

you may use EntityCollection.DirtyEntities property (Returns a readonly collection of entities which are flagged as dirty)

Super

Pat wrote:

The only thing here is that the deleted entities ones would be missing. Would the only way to solve this be to make a boolean column IsDeleted in the table and then transfer the deleted entities as well back to the client where they could be synced?

Walaa wrote:

Yes that's how I may do it.

Would it be possible to change the delete method in such a way that instead of deleting records / rows / entities it sets the IsDeleted column to true? You mentioned "that's how I may do it" would you have a better idea?

Pat wrote:

Would I then send this ChangedCustomer collection back to the client? Then while looping through the ChangedCustomerEntity I would look for the CustomerEntity with the same primary key in the Customer collection and replace the Entity there with the changed one?

Walaa wrote:

Exactly, OR you might add the entities from the OLD collection to the NEW one (not the other way), and with the help of EntityCollection.DoNotPerformAddIfPresent property (default = true), old entities that have a modified version in the new EntityCollection won't get copied.

The difficultie here is that my old collection is already databound to some controls so I would have to update the old collection and not copy it to the new one.

Another point is what would I do with the delete entries in the ChangedCustomers collection? Could I set entities in the Customer collection to deleted and then IsDirty false so that LLBLGen won't try to persist the deletions again to the database the next time the client saves changes?

Thanks Patrick

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-May-2006 14:48:40   

Would it be possible to change the delete method in such a way that instead of deleting records / rows / entities it sets the IsDeleted column to true? You mentioned "that's how I may do it" would you have a better idea?

Instead of doing a delete do an update. If you are going to save modified entities, with some entitied logically deleted (marked as deleted with the IsDeleted property/field), those entities would be saved to the database too with the field IsDeleted modified with the correct values, therefore there is no need for a delete method at all.

The difficultie here is that my old collection is already databound to some controls so I would have to update the old collection and not copy it to the new one.

That's a coding problem, not a logical one, so either you re-bind to the new collection after mixing it with entities from the old collection, or don't bind it and copy the entities back to the old collection after clearing it (ie. 1- copy entities from old collection to the new one - 2- clear the old collection - 3- copy all entities back to the old collection)

Another point is what would I do with the delete entries in the ChangedCustomers collection? Could I set entities in the Customer collection to deleted and then IsDirty false so that LLBLGen won't try to persist the deletions again to the database the next time the client saves changes?

After mixing entities from both collections, you can now remove entities with IsDeleted = true from the collection to be binded and yet saved later to the database.