是的,我想创建一个List<T>
,我的T是用户定义的数据类型,即POCO类,例如用户资料。
为什么:我正在使用MvcJqGrid,我想编写一个用于创建Json数据的通用代码,所以在运行时我会知道从哪个类(表)中需要获取数据。我们可以在运行时创建List <用户定义的数据类型>吗?
我的代码
public ActionResult TestGrid()
{
string spname = Request.Params["storedprocedurename"]; //spname = UserProfile
// i get this from the post data of MvcJqGrid i.e. user when create a jqgrid, in
// a view defines the table/spname from where data gets loaded in grid.
MyEntities _context = new MYEntities();
List<UserProfile> userProfiles = _context.UserProfiles.ToList<UserProfile>();
// here some code to create a json data and return
}
所以这个用户配置我这里硬编码的,如果我在Request.params 得到RoleMaster(例如),所以我怎样才能做到这一点。
配置细节
的EntityFramework版本= 5.0.0.0数据库第一种方法
MVC 4
MvcJqGrid 1.0.9
的.NET Framework 4.5
你可能会得到一个相关的问题一些更多的信息,其中泛型函数在运行时参数化:http://stackoverflow.com/questions/13 397286/appending-string-to-t-to-produce-a-new-class-name/13397489#13397489 – 2013-03-11 11:55:36