Hi there.
Here is a quick description of my setup and issues... I'm lost on how to handle this.
I have 2 different modes of running an appliction.
Scenario 1. User hits a central database server and can perfomr basic CRUD operations (This works fine)
Scenario 2. User selects an object on the database server and chooses to work with it on an offline database. Basically they choose an object and we serialize all the data they need to a file. They then take that file to a laptop that has a blank of our database and we deserialize all of the objects to the blank database on the laptop. This user does their work on the object... and we basically reverse the process and it eventually goes back into the server.
Here is the big issue... It is possible for the users in scenario 1 to do work on the parent only (not the kids) and the users in scenario 2 can update the child information but not the parent. I'm not sure how to allow this to happen without concurrency issues or the fear of overwriting data when bringing the disconnected data back to the database server.
Did that make sense???
Objects:
BusinessBase: Equipment (Scenario 1 can change)
Child: WorkOrders (Scenario 2 can change)
Child: PartOrders (Scenario 2 can change)
Maybe I am missing something, but how can you overwrite parent
data when synchronizing disconnected data?
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: reagan123
[mailto:cslanet@lhotka.net]
Sent: Tuesday, April 15, 2008 2:55 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Not sure what to do in this scenario...
Disconnected Application
Hi there.
Here is a quick description of my setup and issues... I'm lost on how to handle
this.
I have 2 different modes of running an appliction.
Scenario 1. User hits a central database server and can perfomr basic
CRUD operations (This works fine)
Scenario 2. User selects an object on the database server and chooses
to work with it on an offline database. Basically they choose an object
and we serialize all the data they need to a file. They then take
that file to a laptop that has a blank of our database and we deserialize all
of the objects to the blank database on the laptop. This user does
their work on the object... and we basically reverse the process and it
eventually goes back into the server.
Here is the big issue... It is possible for the users in scenario 1 to do
work on the parent only (not the kids) and the users in scenario 2 can update
the child information but not the parent. I'm not sure how to allow this
to happen without concurrency issues or the fear of overwriting data when
bringing the disconnected data back to the database server.
Did that make sense???
Objects:
BusinessBase: Equipment (Scenario 1 can change)
Child: WorkOrders (Scenario 2 can change)
Child: PartOrders (Scenario 2 can change)
Reagan:
Sounds like you need your disconnected app to do a little more work. Specifically:
HTH,
Bruce
Thanks guys..
Bruce, You bring up an interesting concept. What is the best way to compare 2 objects when doing something like this.
I'm still new to the framework and objects etc...
I really appreciate the help.
Sergey,
Everytime a record is saved in our database we update the DateTimeStamp. I guess my issue here was if someone updated the parent record in the connected db then the datetimestamp was updated. When I try to resync.. the disconnected datetimestamp was older and I would get a concurrency check error. I guess this is a seperate problem... :)
Thanks for the reply as well
Reagan:
It helps to think of your parent object in a "wholistic" way (not sure if that's a word or not). In other words, if anything changes in a child object or the fields of the parent itself, the parent object should always be saved and have its stamp updated. In other words, even if no fields changed in the parent object, in reality its stamp did change, because the object "as a whole" changed. I'm fairly certain the CSLA framework handles it this way already, but I've been out of the loop so long that I don't know. Somebody can enlighten me if I'm just preaching to the choir here.
Enough soapbox, though. A great example of very fast side-by-side comparisons of things is Red Gate's SQL Compare (www.red-gate.com). I can't say I know how SQL Compare works internally, but one of the best comparison tools in the .NET framework is Dictionary<K, V> which allows you to create a key-value pair collection and then compare with keys in the dictionary. So you would create a Dictionary for each of the child collections and then compare with the existing object in the primary DB in a side-by-side grid. Dictionaries are extremely fast, even for huge collections, and they eliminate the need for nested looping to compare two collections.
As for the comparison itself, there are a mind-bogglingly large number of ways to do it. The most code would be to just compare the fields yourself in a method. Another way would be to mark the persisted fields or properties with some sort of Attribute, and use reflection to compare only fields / properties with that Attribute.
I would suggest you download a copy of SQL Compare, if nothing else just to see how it works. I'll also give it a plug as being incredibly cool software that paid for itself the first day I bought it.
Copyright (c) Marimer LLC