C# 如何从字符串myTElementName获取远程通信?
我想创建entityframework的通用查询生成器。我正在尝试将泛型类型传递给以下方法C# 如何从字符串myTElementName获取远程通信?,c#,entity-framework,generics,C#,Entity Framework,Generics,我想创建entityframework的通用查询生成器。我正在尝试将泛型类型传递给以下方法ObjectContext.ExecuteStoreQuery方法(String,Object[])。即: BindingSource mybindingSource = new BindingSource(); mybindingSource.DataSource = con.ExecuteStoreQuery<**SomeMethod**(MyTypeName)>(
ObjectContext.ExecuteStoreQuery方法(String,Object[])
。即:
BindingSource mybindingSource = new BindingSource();
mybindingSource.DataSource =
con.ExecuteStoreQuery<**SomeMethod**(MyTypeName)>(
myperfectWorkingSql,
myperfectWorkingSqlsParams
);
BindingSource mybindingSource=newbindingSource();
mybindingSource.DataSource=
con.ExecuteStoreQuery(
myperfectWorkingSql,
myperfectWorkingSqlsParams
);
如何从字符串MyTypeName获取远程通讯?我的SomeMethod()函数应该是什么样的?或者我应该使用哪些方法
或者下面的代码也给出了错误?我错了吗
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 !
函数fooo(类型t){
BindingSource mybindingSource=新BindingSource();
mybindingSource.DataSource=
con.ExecuteStoreQuery(
myperfectWorkingSql,
myperfectWorkingSqlsParams
);
}
错误:找不到类型t或命名空间t!
由于您希望从字符串中获取类型,它将在运行时解析,因此您无法执行此类操作。但是,您可以使用反射来调用此方法并提供类型作为泛型参数
可能存在的副本