ef6.0数据绑定ui控件的数据源处理办法

绑定IQueryable<T>类型数据源到DropdownList, 得到错误“不支持直接到存储查询(DbSet、DbQuery、DbSqlQuery)的数据绑定。应使用数据填充 DbSet (例如通过对 DbSet 调用 Load),然后绑定到本地数据。对于 WPF,绑定到 DbSet.Local。对于 WinForms,绑定到 DbSet.Local.ToBindingList()。”(英文为:Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not  supported. Instead populate a DbSet with data, for example by calling  Load on the DbSet, and then bind to local data. For WPF bind to  DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().

解决办法:将返回的IQueryable<T>数据转换为List对象(加.ToList())

实例:

//导出数据
            var cx_jcyf = from aa in sjklj.cfsftj
                          select aa;
            this.ASPxGridView1.DataSource = cx_jcyf.ToList();
            this.ASPxGridView1.DataBind();
            System.Threading.Thread.Sleep(500);
            //pcwin.Text = "获取集采与否数据,请查看d盘下的mn.xlsx文件";//这个提示不会出现了。采用在SQL中复制数据到excel,可能部分数据出错。
            //实体数据模型5.0选择旧的object...,删除tt文件,数据库表添加,修改,删除都同步更新。数据表重命名,必须在模型中删除再从数据库导入更新。实体数据模型6.0非常不方便
            //ASPxPopupControl1.Windows.Add(pcwin);
            System.Threading.Thread.Sleep(500);
            ASPxGridView1.ExportXlsxToResponse(@"d:\mn.xlsx");


渝公网安备 50011902000225号

渝ICP备18008233号-1