|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Transactions and Typed DataSets, Adapters (Visual Studio 2005)datasets/adapters. Visual Studio 2005 has an excellent code generator for data adapters but at first glance it appears that there is no way to access the necessary properties for transaction management. If you take a look at the generated code you'll notice that the class declaration for the data adapters contains the "partial" modifier. This is very important because it allows you to create a supplementary partial class which will be merged with the generated class. Here's the example partial class I created to go with my generated adapter: using System; using System.Data.SqlClient; using System.ComponentModel; using System.Collections.Generic; using System.Text; namespace Sulzer.HelpDesk.Data.TicketDataSetTableAdapters { /// <summary> /// Partial adapter class /// </summary> public partial class TicketTableAdapter : Component { public void SetTransaction(SqlTransaction pTransaction) { Adapter.UpdateCommand.Transaction = pTransaction; Adapter.InsertCommand.Transaction = pTransaction; Adapter.DeleteCommand.Transaction = pTransaction; Adapter.SelectCommand.Transaction = pTransaction; } } } The only trick to using your own partial class is to use the exact same namespace and classname for your partial class. You now have the ability to create public properties to access any generated private member. Lastly, don't get too crazy with this. Expose what you need to get the job done. I've blogged about it myself
http://codebetter.com/blogs/sahil.malik/archive/2005/10/19/133309.aspx - Sahil Malik [MVP] ADO.NET 2.0 book - http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx ---------------------------------------------------------------------------- Show quote "Mike Smith" <mrsmi***@gmail.com> wrote in message news:1132371871.888749.302580@g49g2000cwa.googlegroups.com... > I've seen several posts related to using transactions and typed > datasets/adapters. Visual Studio 2005 has an excellent code generator > for data adapters but at first glance it appears that there is no way > to access the necessary properties for transaction management. > > If you take a look at the generated code you'll notice that the class > declaration for the data adapters contains the "partial" modifier. This > is very important because it allows you to create a supplementary > partial class which will be merged with the generated class. Here's the > example partial class I created to go with my generated adapter: > > using System; > using System.Data.SqlClient; > using System.ComponentModel; > using System.Collections.Generic; > using System.Text; > > namespace Sulzer.HelpDesk.Data.TicketDataSetTableAdapters > { > /// <summary> > /// Partial adapter class > /// </summary> > public partial class TicketTableAdapter : Component > { > public void SetTransaction(SqlTransaction pTransaction) > { > Adapter.UpdateCommand.Transaction = pTransaction; > Adapter.InsertCommand.Transaction = pTransaction; > Adapter.DeleteCommand.Transaction = pTransaction; > Adapter.SelectCommand.Transaction = pTransaction; > } > } > } > > The only trick to using your own partial class is to use the exact same > namespace and classname for your partial class. You now have the > ability to create public properties to access any generated private > member. Lastly, don't get too crazy with this. Expose what you need to > get the job done. > |
|||||||||||||||||||||||