不支持直接绑定到商店查询的数据 [英] Data binding directly to a store query is not supported

查看:61
本文介绍了不支持直接绑定到商店查询的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



我将我的项目从EF 4.0更新为EF 5.0。从对象上下文到DB上下文。

My Busines-Layer返回IQueryable< T>我可以直接用作DataSource。

 GridView_NeedDataSource(object sender,EventArgs e)
{
GridView.DataSource = Bl.GetSomeData() ;
}

但是自从更新后我发现了这个错误:

 

数据绑定直接不支持商店查询(DbSet,DbQuery,DbSqlQuery)。而是使用数据填充DbSet,例如通过在DbSet上调用Load,然后绑定到本地数据。对于WPF绑定到DbSet.Local。对于WinForms绑定到DbSet.Local.ToBindingList()

这是因为没有实现IListSource GetList。
(MSDN DB-SET LINK)



是真的,我现在要手动实现寻呼逻辑等吗?使用类似".ToList()"的方法对我来说不是一个选择,因为这将结束 在"select * from ..."中


在这里我找到了一个 
类似问题
,但我的观点是,如果我使用加载方法(为什么我必须加载懒惰的东西?),那么我必须在每个视图上手动实现分页逻辑(take,skip).....这不可能是真的; )&NBSP;&NBSP; (这是更新而非降级;))b



非常感谢您的帮助!



最好的问候


Cyril Iselin


pcsupport.ch

解决方案

IQueryable< T>不能是数据源。


如果不调用ToList方法,DbContext可能会在执行查询之前被释放。我不清楚在每个视图上手动实现分页逻辑的含义是什么。您可以编写一个Page方法将页码传递给方法并执行
查询,如下所示:


.Skip((n-1)* 10).Take( 10)


Hello

I updated my Project from EF 4.0 to EF 5.0. From Object-Context to DB-Context.
My Busines-Layer returns IQueryable<T> which I can use directly as DataSource.

GridView_NeedDataSource(object sender, EventArgs e)
{
GridView.DataSource=Bl.GetSomeData();
}

But since the update I recive this error:

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()

This because IListSource.GetList isn't implemented. (MSDN DB-SET LINK)

Is it true, I have now to implement the Paging logic etc. manually? To use a Method like ".ToList()" isn't a option for me, because this will end  in "select * from..."

Here I found a  similar Problem, but my Point is, if I use the Load Method (why I have to load lazy things ?), then I have to implement the paging logic (take, skip) on each view manually..... This can't be true ;)   ( It's an update not a downgrade ;))

Thanks a lot for helping!

Best Greetings

Cyril Iselin


pcsupport.ch

解决方案

IQueryable<T> couldn't be the datasource.

If you don't call ToList method, the DbContext may disposed before executing the query. I'm not clear what's the meaning of implement the paging logic on each view manually. You can write a Page method to pass the page number to the method and execute the query like this:

.Skip((n-1)*10).Take(10)


这篇关于不支持直接绑定到商店查询的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆