0

I want to create a generic query builder to entityframework. To the following method ObjectContext.ExecuteStoreQuery<TElement> Method (String, Object[]) I am trying to pass generic types. That is :

BindingSource mybindingSource = new BindingSource();

mybindingSource.DataSource = 
    con.ExecuteStoreQuery<**SomeMethod**(MyTypeName)>(
        myperfectWorkingSql, 
        myperfectWorkingSqlsParams
    );

How can I get TElement from string MyTypeName? How should be my SomeMethod() function? Or which methods should I use?

or the following code also gives error? Here am I wrong ?

 function fooo ( Type t) {

 BindingSource mybindingSource = new BindingSource();

mybindingSource.DataSource = 
    con.ExecuteStoreQuery<t>(
        myperfectWorkingSql, 
        myperfectWorkingSqlsParams
    );
 }

ERROR: this gives type t or namespace t can not be found !
Yaya
  • 600
  • 1
  • 11
  • 28
  • possible duplicate of [How to use reflection to call generic Method?](http://stackoverflow.com/questions/232535/how-to-use-reflection-to-call-generic-method) – nawfal Jan 17 '14 at 16:40

1 Answers1

1

Since you want to get your type from string, it will be resolved during the runtime, so you can't do such things con.ExecuteStoreQuery<t>. However you can use reflection to invoke this method and provide type as generic parameter

Refer to this answer on how to invoke generic method via reflection

Community
  • 1
  • 1
username
  • 3,378
  • 5
  • 44
  • 75