Follow @RoyOsherove on Twitter

Typed Dataset Q&A


I need to get the best possible performance out of my middle-tier components, so I'm using untyped DataSet objects on the server. But strongly typed DataSet objects are so handy when I build the client portion of the application. Is there a way to get the best of both worlds?


Yes. Have your middle tier return and accept untyped DataSet objects. Use instances of strongly typed DataSet objects in the client application, and use the Merge method to import the contents of the untyped DataSet objects returned by the middle tier.


DataSet objects offer limited validation features. I can't set properties on either an untyped or a strongly typed DataSet to ensure that the value of a column falls between certain limits. Can I add my own code to the class file for added validation?


Of course. You can add validation code to the desired properties of your strongly typed classes, but this was not an intended use of the strongly typed DataSet. Your validation code will not be stored in the .xsd file for the strongly typed DataSet class. If you modify the contents of the .xsd file, Visual Studio .NET will regenerate the class for the strongly typed DataSet and you'll lose the code that you've written.

You have another option: create a new class that inherits from the strongly typed DataSet class and add your validation code there.

[via ADO.NET Core Reference]

This is easily one of the best tech books I've read, especially on this subject. Heartily recommended. They have this Q&A section on every big subject that is covered, and the questions are to the point. Way to go!

More Free Chapters

Book Gripes, Safari Bookshelf, And a .Net Desktops Prize