日期:2014-05-20 浏览次数:20831 次
Context context = new Context(); string esql = "select t.userID,t.userName from tb_user as t where t.sex=false"; ObjectQuery<tb_user> typeRecord = ctx.CreateQuery<tb_user>(esql); ObjectResult<tb_user> typeResult = typeRecord.Execute(MergeOption.NoTracking); this.drpdownlist.datasource = typeResult.toList(); this.drpdownList.datatextfield ="userID"; this.drpdownList.datavaluefield ="userName"; this.drpdownList.databind();
using (NorthwindEntities context = new NorthwindEntities()) { ObjectQuery<Category> query = context.Categories; ObjectResult<Category> result = query.Execute(MergeOption.NoTracking); DropDownList1.DataSource = result.ToList<Category>(); DropDownList1.DataTextField = "CategoryName"; DropDownList1.DataValueField = "CategoryID"; DropDownList1.DataBind(); }
------解决方案--------------------
csdn上问个问题确实垃圾,还不如百度知道
楼主用ef为啥还要用sql方式
CreateObjectSet<T>的方式会不会更好呢