Comparing an in memory entity collection with the database

Posts   
 
    
Posts: 8
Joined: 30-Jul-2007
# Posted on: 02-Jul-2008 11:52:57   

.Net 2.0 SQL Server 2005 LLBLGenPro 2.5 Final (November 5th 2007) SelfServicing Windows Forms Project

I have an entity collection which is generated on a form load. Every few seconds I need to check that no changes have occured on the database which would effect this collection.

Is there a quick way of comparing a collection back to the database, essentially an 'IsDirty' but from the database side rather than the collection itself.

My current thinking is that I just recreate another instance of the same collection and compare the two for changes, but I am hoping there is a quicker/more efficient way of achieving this.

The code I use to generate the collection is simply:

Dim triggers As New KeyDatesCollection
Dim triggersFilter As New PredicateExpression(KeyDatesFields.OurRef = strOurRef)
triggersFilter.AddWithAnd(New FieldLikePredicate(KeyDatesFields.Event, "Portal Trigger:%"))
triggers.GetMulti(triggersFilter)

If I do have to compare 2 collections is there a 'best practice' way of achieving this?

Thanks

Charlie

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 02-Jul-2008 11:55:48   

And what happens if they don't match, would you load and use the database collection instead of the old one in memory?

In this case all you need is to clear the collection in memory and re-fetch it again.

Otherwise you'll have to use your approach.

Posts: 8
Joined: 30-Jul-2007
# Posted on: 02-Jul-2008 11:58:38   

If the database collection is different then yes I need to reload it, but I also need to refresh the users view as well. I don't want to have to do this unless there is a change to reflect on to the UI.

If its definately a comparison then do I have to just loop through the collection comparing each entity?

stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 02-Jul-2008 12:04:48   

You should create a TimeStamp / Datetime column in your table to store the last update date. That would make it easy to know if an entity has been altered since it was fetched.

Posts: 8
Joined: 30-Jul-2007
# Posted on: 02-Jul-2008 12:06:40   

I wish I could...

I think I know what I have got to do now though so thanks.