日期:2014-05-20  浏览次数:20986 次

DataContext.GetTable(Type type)

var result = from obj in context.Plan
                                 where obj.menuId == int.Parse(menuId)
                                 select obj;
                    this.lvDetail.DataSource = result;
                    this.lvDetail.DataBind();


以上这段代码等于是读的Plan表,但是我现在想根据一个tableName的string动态的决定是从哪个表中读数据请问该如何实现,是不是能用DataContext.GetTable(Type type)方法,但是这个方法出来的是ITable,那我在写where子句时表中的字段就点不出了,请问这有什么办法解决?
------解决方案--------------------
var result = from obj in context.Plan
                                 where obj.menuId == int.Parse(menuId)
                                 select obj;
                    this.lvDetail.DataSource = result;
                    this.lvDetail.DataBind();

------解决方案--------------------
大家帮帮忙很急先谢谢大家了
------解决方案--------------------
List<Plan>强制转化结果集 

根据一个tableName的string动态的决定是从哪个表中读数据,没看懂!
------解决方案--------------------
比如
tableName是"Plan"
var result = from obj in context.Plan
                                 where obj.menuId == int.Parse(menuId)
                                 select obj;
this.lvDetail.ItemTemplate = LoadTemplate("~/Template_Plan.ascx");
                    this.lvDetail.DataSource = result;
                    this.lvDetail.DataBind();

tableName是"Market"

var result = from obj in context.Market
                                 where obj.menuId == int.Parse(menuId)
                                 select obj;