Re: Updating DB with large collections

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Sam Santiago (ssantiago_at_n0spam-SoftiTechture.com)
Date: 10/13/04


Date: Wed, 13 Oct 2004 16:43:54 -0700


> Although the "dirty" flag is a possibility, it is a "dirty" one. :-) And
in
> case of external systems/other UI that will update my system, I will have
to
> make sure that the flags were used.

The "dirty" flag would not be visible to any external systems or clients of
your objects. The flag would purely be an internally managed state
mechanism.

> The collections can be serialized to XML strings and sent to the DB as
such.

Are you saving the entire collection in the DB as an XML string? I thought
these collections were discrete objects where each object would have to be
saved in the DB if modified. Concurrency is always an issue and should be
dealt with by the data layer - never update the DB if the object to be saved
has stale data. If you have dealt with concurrency properly, then whether
or not you update all fields in a row or just a subset of fields in a row
becomes purely a performance issue and not a data integrity issue.

Have you seen this application block on MSDN:

Data Access Application Block
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp

Thanks,

Sam

-- 
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTechture.com
_______________________________
"gwenda" <gwenda@discussions.microsoft.com> wrote in message
news:8DA59B37-5648-45EE-B875-18B2BA3FB552@microsoft.com...
> Hi Sam,
>
> Thanks for your answer. There are few points I would like to point out
> regarding your answer:
>
> Generally, I intend to update all the properties of any object. However, I
> don't want to update (if I don't have to) two types of properties:
>
> Collections -usually contains other objects. I would like to
> insert/update/delete only the objects in the collection that were modified
by
> the client. Some of my objects contain rather large collections and some
may
> contain more than one property which is a collection.
>
> Large sub-objects - that is an object which is contained in the main
object
> and is large enough to reconsider updating it for no reason.
>
> Performance is indeed a consideration but another motive was the DB
> concurrency. Naturally those sub-objects and collections usually reside in
> other tables in the DB and may have been modified but other users.
Although I
> have a mechanism to prevent it, I've learned that those big updates which
> wipe everything an re-insert new date usually turn to be messy.
>
> Although the "dirty" flag is a possibility, it is a "dirty" one. :-)  And
in
> case of external systems/other UI that will update my system, I will have
to
> make sure that the flags were used.
>
> I was thinking about having my business component in the middle tier
> comparing the cached object with the modified object. According to the
> comparison results the relevant main-object and/or sub-objects and/or
> collections objects will be sent to the data layer components. The
> collections can be serialized to XML strings and sent to the DB as such.
But
> this seems like a complex solution to what I imagined should be quite
common
> problem and I kind of hoped for a "by-the-book" solution.
>
> Thanks Again,
>
> Gwenda
>
>
>
>
>
> "gwenda" wrote:
>
> > Hi,
> > My application is composed of business entities which are in the form of
> > classes instances. Some of these entities contains large arraylists of
other
> > entities. These entities are being sent to the client - where the user
might
> > add/modify/delete some items in the arraylists. Natuaraly, I don't want
to
> > send to the DB the part of the entities which the user hadn't changed.
> > I'm keeping a copy of the original entity in my middle tier so when the
> > modified entity is returned from the client I can check what was changed
and
> > according to this decide what to send to my data layer.
> > The question is what would be the best method to do the comparison?
> > I was advised to use dataset. I've tried to serialize my arraylists  -
both
> > of the original object and the modified one - into datasets and use the
merge
> > method. But I couldn't get it to work (note that the client is not
getting a
> > dataset but rather a class instance). Is there a way to make it work
> > following the above scenario? If there isn't what would be the most
> > appropriate way to perform that kind of operation?
> > Thanks,
> > Gwenda