代码隐藏中的 Silverlight DomainDataSource 未加载所有行
我在 Silverlight 4 中有一个域数据源。我在后面的代码中设置它,并且我还使用 RadDataPager 和 RadGridView。
DomainDataSource dds = new DomainDataSource();
dds.QueryName = "MyQueryName";
dds.DomainContext = ctx;
dds.LoadSize = 10;
dds.PageSize = 10;
dds.AutoLoad = true;
radDataPager1.PageSize = 10;
radDataPager1.Source = dds.Data;
radGridView1.ItemsSource = dds.Data;
dds.Load();
第一次加载时,dds.Data.Count 为 8,尽管 dds.Data.PageSize 为 10,但网格视图中仅显示 8 个项目。在我翻到下一页后,所有 10 个对象都已加载就像他们应该的那样。
我是 Silverlight 的新手,不知道这里发生了什么。我加载数据错误吗?有什么想法吗?
I have a domain data source in Silverlight 4. I'm setting it up in the code behind, and I'm also using a RadDataPager and RadGridView.
DomainDataSource dds = new DomainDataSource();
dds.QueryName = "MyQueryName";
dds.DomainContext = ctx;
dds.LoadSize = 10;
dds.PageSize = 10;
dds.AutoLoad = true;
radDataPager1.PageSize = 10;
radDataPager1.Source = dds.Data;
radGridView1.ItemsSource = dds.Data;
dds.Load();
The first time this loads, the dds.Data.Count is 8, and only 8 items show up in the grid view, even though the dds.Data.PageSize is 10. After I page to the next page, all 10 objects are loaded like they should be.
I'm new to Silverlight, and have no idea what is going on here. Am I loading the data wrong? Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此行为可能是由于模型类中的 Key 属性设置错误造成的。如果在结果查询中,具有Key字段的行重复,则DataGrid将只取第一个。
示例(书店信息):
您的结果类 (BookPriceInfo.cs) 如下所示:
如果您有从数据库返回的查询结果:
那么 DataGrig 将仅显示以下内容:
发生这种情况是因为 DataGrid 将通过标记为
Key(从具有相同 BookId 的所有行中仅获取第一行),因为它对于所有行应该是唯一的。
解决方案
从具有重复值 (BookId) 的字段中删除
Key
属性,并将其设置为所有行都具有唯一值的字段(您可以添加一些列,例如 BookPriceId,这将是唯一的)。查询结果:
之后您应该看到查询返回的所有行。
希望这有帮助:)
This behavior can be caused by wrong set of Key attribute in your model class. If in the result query, rows with Key field are duplicated, then DataGrid will take only first.
Example (book store info ):
Your result class (BookPriceInfo.cs) looks like this:
And if you have query result returned from database :
Then DataGrig will show only this :
this happens because of DataGrid will 'distinct' the results by field marked as
Key
(get only first row from all rows with same BookId), because it should be uniq for all rows.Solution
Remove
Key
attribute from field which will have duplicated values (BookId) and set it to field which will have uniqe values for all rows (you can add some column like BookPriceId, which will be uniqe).Query result:
After that you should see all rows returned by query.
Hope this helps :)