-1

i would like to make a linq to sql provider that allow to me to query onto a table that is nor mapped in the datamodel nor known.

I only know a table's alias that i use to query another known table for translation (from the alias to the real table name), after that i will using standard linq to query the real table, read data, and put each results into a dynamic's object.

To achieve that i suppose i need to define a custom linq provider that will manipulate the expression tree, and then call standard linq to sql; but at moment i don't know how do it.

So my aim is that i would write code like this :

 List<dynamic> rows = form book in context.Book
                      where book.Author = "Author"
                      select book;

Thank in advance for any suggestion.

Skary
  • 1,322
  • 1
  • 13
  • 40
  • http://www.codeproject.com/Tips/652766/Dynamically-Build-LINQ-to-SQL-Classes-at-Runtime this seems what i looking for. Now i need to test it a bit and then i can confirm that. – Skary Oct 19 '14 at 15:02

1 Answers1

0

You can use Reflection:

PropertyInfo table = typeof(ContextType).GetProperty(TableName);

from book in table.GetValue(Context)
...
Raein Hashemi
  • 3,346
  • 4
  • 22
  • 33
  • You are right, i just edited my quesion. As compiler trust you when you write : var a = myDynamic.property I would like linq trust me when i write "context.AnyNames" or "x.AnyProperty" – Skary Oct 19 '14 at 07:07