S
Sahil Malik [MVP C#]
Hey John,
Easier to read doesn't necessarily mean it works better. That code snippet
below is rather simplistic. When you do get my book, read up the concurrency
and updating data issues in Chapters 9 and 10. There is no frickin' way
TableAdapters can make work with that.
Even in my book, Chapters 6 and 8, I agree the below is easier on eyes.
Strongly Typed Datasets have a FindByCustomerID(Int32) rather than
Find(object). In perspective of architecture (and I discuss this frequently
in my book and on my blog), I like to view systems as a combination of
connected and disconnected. (Assuming every system is a method of
manipulating data).
Disconnected portions are super important in any serious app - although a
100% disconnected or a 100% connected system is a reflection of bad design.
SO when we talk about Disconnected systems, you need something to store and
transport your disconnected data in. Here you have two choices -
a) Dumb data buckets - datasets and strongly typed datasets. or
b) Business objects - smart or otherwise
Business objects is a whole another topic and I like to refer to Rocky
Lhotka as the Guru on those. But when it comes to DataSets, they will get
you through 90% of the tasks you need, but in very specific situations, such
as saving hierarchical data - they fall sorely short of what you may need.
While I want to lean towards handwritten apps, it would also be wrong to
outright critcize TableAdapters into banishment/uselessness. Truthfully I
use them at times. This is even more true for DataSets. But it would be
sorely incorrect to say that "That is the new way of doing things, and
forget handwritten code". In certain specific situations you are *better
off* using strongly typed datasets over non strongly typed. It's all gray -
it depends on the situation, no black or white. But in MOST situations you
want a handwritten app. TableAdapters donot fit most real world requirements
IMO.
But I'll leave you with a practical instance of "Where you'd prefer a
strongly typed ds over a non strongly typed".
Say you have 2 columns - Price, Tax. And you want a third calculated column
TotalPrice = Price + Tax.
So if you had non strongly typed dataset - You would have to .. umm fill the
data, add a column then set the expression .. but that won't work. Because
it would add 1.05 and 0.25 as 1.050.25 (as strings). Why? Because it doesn't
know the data types. So now you can set the data type .. right? NOPE - you
need to set DataTypes *before* you fill the data. So you need to write code
to maintain data types, and then fill data - what a pain in the ar*se.
Especially because now when the structure changes, my programattical schema
declarations are all over my code - hard to trace. .. Man I wish there was
an XSD I could modify here . Compared with Strongly Typed Datasets - you
don't specify the schema, it comes with the schema at runtime. Ain't that
cool
So in very very isolated incidents, strongly typed ds may even be preferable
over non st-datasets. Ditto for TableAdapters, I'm sure in a specific
situation you may prefer to use them over other choices - but it would be an
exception.
I think my book will arm you with sufficient knowledge to make these
judgement calls as you go along architecting an app. Or hey if there are
questions I'm around , (as are many other smart individuals in this NG).
- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
__________________________________________________________
Easier to read doesn't necessarily mean it works better. That code snippet
below is rather simplistic. When you do get my book, read up the concurrency
and updating data issues in Chapters 9 and 10. There is no frickin' way
TableAdapters can make work with that.
Even in my book, Chapters 6 and 8, I agree the below is easier on eyes.
Strongly Typed Datasets have a FindByCustomerID(Int32) rather than
Find(object). In perspective of architecture (and I discuss this frequently
in my book and on my blog), I like to view systems as a combination of
connected and disconnected. (Assuming every system is a method of
manipulating data).
Disconnected portions are super important in any serious app - although a
100% disconnected or a 100% connected system is a reflection of bad design.
SO when we talk about Disconnected systems, you need something to store and
transport your disconnected data in. Here you have two choices -
a) Dumb data buckets - datasets and strongly typed datasets. or
b) Business objects - smart or otherwise
Business objects is a whole another topic and I like to refer to Rocky
Lhotka as the Guru on those. But when it comes to DataSets, they will get
you through 90% of the tasks you need, but in very specific situations, such
as saving hierarchical data - they fall sorely short of what you may need.
While I want to lean towards handwritten apps, it would also be wrong to
outright critcize TableAdapters into banishment/uselessness. Truthfully I
use them at times. This is even more true for DataSets. But it would be
sorely incorrect to say that "That is the new way of doing things, and
forget handwritten code". In certain specific situations you are *better
off* using strongly typed datasets over non strongly typed. It's all gray -
it depends on the situation, no black or white. But in MOST situations you
want a handwritten app. TableAdapters donot fit most real world requirements
IMO.
But I'll leave you with a practical instance of "Where you'd prefer a
strongly typed ds over a non strongly typed".
Say you have 2 columns - Price, Tax. And you want a third calculated column
TotalPrice = Price + Tax.
So if you had non strongly typed dataset - You would have to .. umm fill the
data, add a column then set the expression .. but that won't work. Because
it would add 1.05 and 0.25 as 1.050.25 (as strings). Why? Because it doesn't
know the data types. So now you can set the data type .. right? NOPE - you
need to set DataTypes *before* you fill the data. So you need to write code
to maintain data types, and then fill data - what a pain in the ar*se.
Especially because now when the structure changes, my programattical schema
declarations are all over my code - hard to trace. .. Man I wish there was
an XSD I could modify here . Compared with Strongly Typed Datasets - you
don't specify the schema, it comes with the schema at runtime. Ain't that
cool
So in very very isolated incidents, strongly typed ds may even be preferable
over non st-datasets. Ditto for TableAdapters, I'm sure in a specific
situation you may prefer to use them over other choices - but it would be an
exception.
I think my book will arm you with sufficient knowledge to make these
judgement calls as you go along architecting an app. Or hey if there are
questions I'm around , (as are many other smart individuals in this NG).
- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
__________________________________________________________