You are not Logged in
Would you like to Login or Register

Today is: Friday, 21 November, 2008
Check this months hot topics

Extending Strongly Typed Datasets

Strongly Typed Datasets are a rather nice addition to VS2005 (they don't lend themselves well to acronyms however)

You still need to create a database and tables and realationships but using STDs saves a writing huge amount of code.

If this code were generated by hand or by a utility such as CodeSmith then the classes could just be edited to add function as required (though most of the benefits of code generation are lost once the generated code is edited).

The STD source is of course auto-generated from the xsd file, a convienient way to view the C# source is to type the STD name and use the context menu to 'Go To Definition', or press F12.

This will open a c# source file with a guid name. You can edit this file but it will be overwritten each time the xsd is compiled.

You can add new methods and properties to the STD classes by using partial classes. First create a new cs (or vb if you swing that way) file with the filename same as your xsd - for example 'ObjectSTD.cs'.

Edit the class definition adding the partial keyword as below.

You can add a new method to the ObjectRow class within the ObjectSTD class with the following code...

public partial class ObjectSTD
{
    public partial class ObjectRow
    {
        public string funcToString()
        {
            return string.Format("({0}) {1}", ObjectId, Description);
        }
    }
}

Note that private properties and methods are available and intellisense supports these.

kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Dave Howard Skype
Author : Dave Howard
Published : Sunday, 23 July, 2006

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Comments

Paul Hayman said:

Are you saying that from within the partial class, the private methods and properties (which you would expect to be able to access) aren't available? Is this just an IntelliSence thing, does it compile.

July 23, 2006 - 9:39 PM

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views