views:

56

answers:

3

Hey guys,

I'm looking for a good solution to make my life easier with regards to writing/reading to a SQL Server DB in a dynamic manner. I started with Entity-framework to make my life easier to begin with, but as the software become more general and config driven I'm finding that Entity becomes less and less appropriate because it relies on specific objects defined at design time.

What I'd like to do.

  • Generate Tables/Fields at runtime.
  • Select rows from tables by table name with unknown schema into a generic data type (eg Dictionary)
  • Insert rows to tables by table name using generic data types (dictonary, where the string maps to field name), where the data type mapping between typeof(object) and field type is taken care off.

I've started implementing this stuff myself, but I imagine someone has already has already done it before.

Any suggestions? Thanks.

A: 

The iBATIS.NET (now MyBatis.NET) Data Mapper framework doesn't automatically generate tables or fields at runtime, but it does allow you to select and commit data via Dictionary objects.

It's probably not going to suit your needs completely (it's kind of tedious to set up, but pretty easy to maintain once it is), but it might be worth a look. Here's a link to the online documentation.

Other popular frameworks might do the same or similar, such as NHibernate.

Cory Larson
A: 

I'm having trouble understanding how what you are describing is any different than plain old ADO.NET. DataTables are dynamically constructed based on a SQL query and a DataRow is just a special case of an IndexedDictionary (sometimes called an OrderedDictionary where you can access values via a string name or an integer index like a list). I make no judgment as to whether choosing ADO.NET is actually right or wrong for your needs, but I'm trying to understand why you seem to have ruled it out.

mattmc3
I have to admit I just never thought to try that! Have never generated datatables before, just used them to get some data. I'll check to see if it meets my needs. Cheers.
Bogdan Kiselitsa
A: 

Looks as if this question is related.

John