views:

68

answers:

5

i'd like to be able to query any number of databases with different table layouts, return a datatable then use that datatable to build a strongly typed object. Is there anything out there that does this or comes close without having to code for each different table layout?

Thank you in advance!

Zac

A: 

I'm not sure this is exactly what you're looking for, but the datatable base type has a method called GetTypedTableSchema() that returns an XmlSchemaSet object. You may be able to use this as a roadmap to translate a typed datatable into a strongly typed object.

Joel Etherton
A: 

Assuming you're trying to get Intellisense benefits - go the code generation route against your tables.

Brett Veenstra
A: 

No. This is not possible.

In case of typed-datasets, If you need typed-safety at run-time, the type needs to be defined at design-time or you are going to use plain datasets/datatables for your database operations.

this. __curious_geek
+1  A: 

May be you can use LINQ and return Anonymous Types http://msdn.microsoft.com/en-us/library/bb397696.aspx

eg:

var result = (from itm in list where itm.StateID==2 select new {Name = itm.Name, State=Itm.StateID});
Shoaib Shaikh
A: 

You could try subsonic.

It does exactly that, using code generation via T4 templates.

Get more information at http://subsonicproject.com/

Cheers,

André

andrecarlucci