tags:

views:

241

answers:

1

I'm using linq to sql. I have a table in dbml file that some of its fields can be generate dynamically (at run time). Is there any way to add fields to a table dynamiccaly , or add a class to dbml file dynamically?

A: 

You can't add a class to the DBML file dynamically, but you can create a TypeBuilder instance to create a class at runtime with the appropriate Table and Column attributes and then use that class in your queries.

The problem with this is that you have to access this through reflection, including most of the calls to generate the queries (since you have no way of knowing at compile time what to call those members).

That said, your best bet would be to use a more generic container (depending on your data shape) and then project that into a sequence of KeyValuePair instances (or some other structure) which would hold the value keyed on the name of the dynamic field.

casperOne
Thank you . In regards to your answer, Here is the link that I have found really usefullhttp://blog.bodurov.com/How-to-Bind-Silverlight-DataGrid-From-IEnumerable-of-IDictionary
Naseem