HighTechTalks DotNet Forums  

Should I pass/hold DataRow or use Class?

Dotnet Framework (Performance) microsoft.public.dotnet.framework.performance


Discuss Should I pass/hold DataRow or use Class? in the Dotnet Framework (Performance) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
John Mark Howell
 
Posts: n/a

Default Should I pass/hold DataRow or use Class? - 10-16-2004 , 02:24 PM






I hope someone can provide some insight here. I'm trying to determine the
best method of retaining and passing around data that has been read from the
database. One thought is to Inherit From DataRow and provide type-safe
methods, another is to create a dummy class that has nothing but public
variables. The problem I see with the first method is the overhead in
carrying around a DataRow, the problem with the second method is that every
time I pull data, I have to move it into the dummy class. Can someone
intimate with the CLR internals provide some insight as to which method may
be better and why?

// Sample using DataRow
// DataRows are passed between the Business Layer and the Data Layer
public class MyCar {
private DataRow _rowData;
public String CarName { get { return _rowData["CarName"].ToString(); } }
pubilc Int32 CarID { get { return
Convert.ToInt32(_rowData["CarName"].ToString(); } }
public MyCar(DataRow row) {
_rowData = row;
}
}

// Sample using a dummy class
// MyCarData is passed between the Business Layer and the Data Layer, the
Business
// layer no longer needs to know what a DataRow is.
class MyCarData {
public String CarName = String.Empty;
public Int32 CarID = Int32.MinValue;
}
public class MyCar {
private MyCarData _data = new MyCarData();
class MyCar(DataRow row) {
_data.CarName = row["CarName"].ToString();
_data.CarID = Convert.ToInt32(row["CarID"]);
}
}



Reply With Quote
  #2  
Old   
Alvin Bruney [MVP]
 
Posts: n/a

Default Re: Should I pass/hold DataRow or use Class? - 10-18-2004 , 10:43 PM






windows forms or webforms?

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"John Mark Howell" <jmarkhowell (AT) hotmail (DOT) com> wrote

Quote:
I hope someone can provide some insight here. I'm trying to determine the
best method of retaining and passing around data that has been read from
the database. One thought is to Inherit From DataRow and provide type-safe
methods, another is to create a dummy class that has nothing but public
variables. The problem I see with the first method is the overhead in
carrying around a DataRow, the problem with the second method is that every
time I pull data, I have to move it into the dummy class. Can someone
intimate with the CLR internals provide some insight as to which method may
be better and why?

// Sample using DataRow
// DataRows are passed between the Business Layer and the Data Layer
public class MyCar {
private DataRow _rowData;
public String CarName { get { return
_rowData["CarName"].ToString(); } }
pubilc Int32 CarID { get { return
Convert.ToInt32(_rowData["CarName"].ToString(); } }
public MyCar(DataRow row) {
_rowData = row;
}
}

// Sample using a dummy class
// MyCarData is passed between the Business Layer and the Data Layer, the
Business
// layer no longer needs to know what a DataRow is.
class MyCarData {
public String CarName = String.Empty;
public Int32 CarID = Int32.MinValue;
}
public class MyCar {
private MyCarData _data = new MyCarData();
class MyCar(DataRow row) {
_data.CarName = row["CarName"].ToString();
_data.CarID = Convert.ToInt32(row["CarID"]);
}
}




Reply With Quote
  #3  
Old   
John Mark Howell
 
Posts: n/a

Default Re: Should I pass/hold DataRow or use Class? - 10-19-2004 , 11:25 AM



WinForms. But what would that have to do with it?

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote

Quote:
windows forms or webforms?



Reply With Quote
  #4  
Old   
Alvin Bruney [MVP]
 
Posts: n/a

Default Re: Should I pass/hold DataRow or use Class? - 10-19-2004 , 04:06 PM




The overhead of each approach you presented is not a major concern since
both essentially do the same thing.
Rather, you should focus on how you are going to maintain data consistency
between your wrapped class and the underlying datastore. This is where the
inheritance has the edge because you will be able to re-use the data
consistency functionality already available in the data row.{Well, it really
isn't in the data row but it is part of the dataset and datatable).


Quote:
WinForms. But what would that have to do with it?
these different architectures have different ways of storing global
information

Essentially, your question boils down to whether or not to build a data
delivery tier (wrapping the data row in a class). Tiers make sense if the
application is large and different layers need to be clean and decoupled.
Decoupling adds flexibility so if you wanted to obtain data from a
webservice instead of the database, your class can be updated with the
necessary functionality without breaking the calling code.

For small projects, tiers are overkill for obvious reasons. A lot of it has
to do with the overhead and maintenance inherent in a tier - like you
pointed out.


--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"John Mark Howell" <jmarkhowell (AT) hotmail (DOT) com> wrote

Quote:
WinForms. But what would that have to do with it?

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%23pvi8VYtEHA.2804 (AT) TK2MSFTNGP14 (DOT) phx.gbl...
windows forms or webforms?





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.