Re: Transactions in ADO.Net 2 strongly-typed datsets.
- From: "Sahil Malik [MVP]" <contactmethrumyblog@xxxxxxxxxx>
- Date: Mon, 4 Apr 2005 12:46:08 -0400
Glenn,
I recently finished the chapters concerning this portion of my upcoming
ADO.NET 2.0 book, so let me try and answer your question.
ADO.NET 2.0 has a new thing called TableAdapters and that is fairly easy to
understand, just experiment/play with creating a strongly typed dataset -
add a query, table adapter - you will figure it out. I personally don't like
that for one reason - it does not offer me the level of concurrency control
I need. It is vastly improved than 1.1 though, but still in an enterprise
app - it does not allow me to fix and twist the design to my liking :). It
still emphasizes on running it's own queries and completely ignoring my data
layer - so its not perfect - but it's better than what it used to be.
Let me address the more enterprise level - get your hands dirty - have full
control method though - which is what I'd prefer to use, simply because it
allows me to use design patterns and data layers etc.
You have more than one tables, with a relation between them right? You need
to filter out Updated rows, (Modified), Added and deleted rows one by one
and use a data adapter to modify ONLY those rows.
Now the order of execution is important, so if there is a one to many
relationship between Group and Groupmembers, you need to first execute
Inserts on Group, then Updates on Groups, followed by Inserts on
GroupMembers, Updates on Group members, and wrap these up by calling Deletes
on Groupmembers, and Delete on Group Members.
Thus you need to
a) Create dataadapters for particular tables, and specify the
updatecommand./deletecommand/insertcommand on them.
b) Execute the Datadapter.Update(DataRow[]) overload, in which you pass in
rows in a particular rowstate - which can be filtered using the
datatable.select method.
You can make the whole thing transactional by doing a
connection.open
connection.begintransaction
... specify the transaction property to all the IUD commands.
tran.commit
conn.close
Multiple table hierarchical "save" (insert/update/delete) is not trivial,
but not impossible either. Previous data access architectures were even
kludgier in comparison - atleast it works now :)
- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/
<gwolinsky@xxxxxxxxxxxxxxxx> wrote in message
news:1112630101.283533.243380@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Here's the scenario: I have a custom object that represents a group in
> our law firm. For each group, there are many members of that group.
>
> Now, the group object exposes a property that is a strongly-typed
> datatable of the member records. The UI programmer will add/delete
> records from this datatable as the user adjusts the members of the
> group.
>
> Then, the Update method of the group object will not only update it's
> normal properties (name, description, etc.) but will call the update
> method of the adapter for the datatable to write the changes to the
> members.
>
> My question as a ADO.Net 2 newbie is this: How to I wrap the group
> object changes and the changes written by the update in the datatable
> in the same transaction?
>
> I knew how to do this in ADO.Net 1.x, but the properties exposing the
> insert, update, delete command objects in the datatable are not there.
>
> What am I missing?
>
> Any help would be GREATLY appreciated.
>
> Sincerely,
> Glen Wolinksy
>
.
- Follow-Ups:
- Re: Transactions in ADO.Net 2 strongly-typed datsets.
- From: gwolinsky
- Re: Transactions in ADO.Net 2 strongly-typed datsets.
- References:
- Transactions in ADO.Net 2 strongly-typed datsets.
- From: gwolinsky
- Transactions in ADO.Net 2 strongly-typed datsets.
- Prev by Date: Re: Retrieving datarows using DataTable.Select method and adding it to new DataTable
- Next by Date: Re: ExecuteNonQuery returns ORA-01036 illegal variable name/number
- Previous by thread: Transactions in ADO.Net 2 strongly-typed datsets.
- Next by thread: Re: Transactions in ADO.Net 2 strongly-typed datsets.
- Index(es):
Relevant Pages
|