I’m in the process of rewriting our application. We are building DataMappers to work in our DAL. My question relates to the situation where I have a complex object from the BLL that get’s passed to the DataMapper to be persisted.
Let’s say this object has a lot’s of properties including lists of other objects.
i.e…
public class Customer
{
public String name;
public String age;
public String ShoeSize;
public List<Address> a;
public List<Orders> o;
{
In a situation where maybe “age” was the only field that was updated in the BLL.
What’s a good practice for persisting this to the database?
Would you persist the entire structure? or How can I structure this so that my DataMapper would know which fields changed so that I didn’t have to update the entire structure in the database? I guess I could have some kind of IsDirty field for each property, but that could get messy really quick.
Thanks,
MW
If you keep the original object in memory and pass in a new “version” with the changes, you could check the new object for changes and only save that.
After the update you replace the original object with the new. But be aware of concurrency issues if you have multiple threads.