Dynamic queries

Sep 12, 2014 at 9:07 PM
Edited Sep 12, 2014 at 9:08 PM
All of the examples are in the form: "from customer in _db.CustomerSet...". I need to be able to do something like "from entity in _db[tableName]...", where tableName is a string variable. Any suggestions for how I might be able to accomplish this? i'm searching for "dynamic linq" but not finding much that I can successfully apply to this library.
Sep 16, 2014 at 11:12 AM
Edited Sep 16, 2014 at 11:13 AM

I think one migth be able to do that if one writes methods like
public static Expression GetTableByName(this TabularContext context, string tableName) {
       var tableProperty = contex.GetType().GetProperties().First(p => p.Name == tablename)
       var type = typeof(TabularTable<>).MakeGenericType(tableProperty.Type);
       var instance = Activator.CreateInstance(type, context.Provider);
       var tableExpression = Expression.Constant(instance as IQueryable);
       return tableExpression;
I don't think that this example would just work as is and since the contexts TabularTableMappingAttribute contains the actual table name form the database, it might worth to check against that instead of property name.

I will try to do something to illustrate the idea in the coming weeks.