Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# DataSet Factory Class
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01311453
Message ID:
01311478
Views:
24
>Now that I have invested some time learning how to use DataSets, I'v been thiking that if I created a class for each table, I would have dozens of classes.
>
>So what not create a generic class that gives back a typed dataset based on a value passed in. For example, if I want to
>create a customer dataset, then pass 'customer', for invoice headers, pass 'invhead' and so on.
>
>The code would then be smart enough to create the appropriate dataset class to return. I have no idea what would be
>involved in creating this, but the concept seems beter than one class for each table.
>
>I'm open to suggestion. If anyone has done this, I would be interested in how to proceed.

So are you just planning on having the strongly-typed classes generated the way you're current doing it and just have a factory which returns the correct type based on a name, or are you wanting to build these strongly-typed classes on the fly?

If you just want a factory class, that's doable. There is also a lot of example code around which you can use as a basis for this.

If you mean you want to generate the strongly-type classes on the fly, then you can't really do this. The first problem you'll run into is, "how do I create a class and add properties at runtime". The answer you'll get is, you can't (at least, you're really not going to be happy with what's involved, the constraints, etc) - use one of the Dictionary or other name/value types already available. At that point, you might as well stick with what VS gives you via the strongly-typed DataTable classes.

What a lot of developers do is have some tool which generates all of the classes for you, so it's not something you have to think about doing. The difference is that they actually generate code, which is then compiled into your application vs trying to do this at runtime.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Reply
Map
View

Click here to load this message in the networking platform