TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

typed-DataSet Designer Rocks! (How about making one for Custom Classes & Collections?)

One of the really cool features of Visual Studio is the ability to create typed-DataSets based on XSD using a designer. A typed-DataSet gives you strongly-typed access to columns such as a person's name being a String or person's age being an Int32. You also get "null checking" and the ability to set values to "null."

PersonDataSet personData = new PersonDataSet();

PersonDataSet.PersonRow person = personData.Person[0];

person.Name = "blah";

person.Age = 33;

person.IsAgeNull();
person.IsNameNull();

I wish there were the same kind of designer available for custom classes. Not everyone likes using DataSet, and not everyone can use DataSets. And with DLINQ on its way, you can't tell me that DataSets are the future either. Now before you mention using xsd.exe /c, that really doesn't give me the formatting I'm looking for. The same is true using the class designer in Visual Studio. If you add properties in the class designer, you end up with ugly code like this:

public class Person {

    public string Name {

        get {

            throw new System.NotImplementedException();

        }

        set {

        }

    }

 

    public int Age {

        get {

            throw new System.NotImplementedException();

        }

        set {

        }

    }
}

The alternative is to use the prop expansion to get what I really want - a private field to go with my property by default:

private string _name;

 

public string Name {

    get { return _name; }

    set { _name = value; }
}

However, the prop expansion does a couple of goofy things - it places the private field declaration right above the property procedure code instead of at the top of the class. You can of course work around this by using the prop expansion at the top of your class (if you are like me, you prefer having your field declarations at the top of your class). That leaves us with being able to check for "dirty" field values (similar to the typed-DataSet IsSomethingNull() and SetSomethingNull() methods). It also leaves us with the fact that if I have a large number of properties, who wants to deal with using the prop expansion when we could have a perfectly good designer available like the typed-DataSet folks get to enjoy? I don't want to have to tweak xsd.exe or buy a CodeSmith license. This is something that could easily be included with Visual Studio IMO. What I would like to see included with Visual Studio is something similar to a very lame mock-up utility I made  in a few minutes illustrated below, or better yet, the same kind of typed-DataSet designer for custom classes & collections.

 


Digg!

posted on Sunday, February 19, 2006 2:07 PM

Feedback

# re: typed-DataSet Designer Rocks! (How about making one for Custom Classes & Collections?) 2/19/2006 6:46 PM Doug

i spent the better part of this weekend looking at these myself. i do agree they are cool.... but... i wonder what the role of a good BL is. seriously i am actually wondering that.

especially since most of my apps the BL doesn't do much besides providing data typing. in my now almost 3 year old model i have a base business class with all the good save, delete, SetNull IsNull methods and my specialized business classes inherit from the base class and just have a bunch of property gets/sets that do the cast and call into the base classes protected member variable that is a dataset. i changed it a little over the years. i even went to a 2 base class model one that wraps the dataset and one that wraps the datarow.

very similiar to what the typed dataset does, just with composition instead of inheritance.

i could see someone making the claim tha with the typed datasets they don't need a dal or a BL. esp with the ability to easily add what little business logic you might have in new partial class that gets generated with your typed dataset. im not sure they would be wrong either.

so long story short i probably will give them a chance again in 2005 but its hard to teach this old dog new tricks.

Doug