Reputation: 387
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
Upvotes: 1
Views: 156
Reputation: 6306
You could try subsonic.
It does exactly that, using code generation via T4 templates.
Get more information at http://subsonicproject.com/
Cheers,
André
Upvotes: 1
Reputation: 4585
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});
Upvotes: 1
Reputation: 43217
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.
Upvotes: 0
Reputation: 48524
Assuming you're trying to get Intellisense benefits - go the code generation route against your tables.
Upvotes: 0
Reputation: 37543
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.
Upvotes: 0