代码隐藏中的 Silverlight DomainDataSource 未加载所有行

发布于 2024-09-16 18:24:28 字数 545 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2024-09-23 18:24:28

此行为可能是由于模型类中的 Key 属性设置错误造成的。如果在结果查询中,具有Key字段的行重复,则DataGrid将只取第一个。

示例(书店信息):
您的结果类 (BookPriceInfo.cs) 如下所示:

    public class BookPriceInfo {
      [DataMember]
      [Key]
      public int BookId { get; set; }
      [DataMember]
      public string Name {get; set; }
      [DataMember]
      public string StoreName {get; set;}
      [DataMember]
      public decimal Price {get; set;}
   }

如果您有从数据库返回的查询结果:

BookId | Name | StoreName | Price 
1 | book1 | store1 | 70.00
1 | book1 | store2 | 69.99
2 | book2 | store1 | 40.00
2 | book2 | store2 | 39.99

那么 DataGrig 将仅显示以下内容:

BookId | Name | StoreName | Price 
1 | book1 | store1 | 70.00  
2 | book2 | store1 | 40.00

发生这种情况是因为 DataGrid 将通过标记为 Key(从具有相同 BookId 的所有行中仅获取第一行),因为它对于所有行应该是唯一的。

解决方案

从具有重复值 (BookId) 的字段中删除 Key 属性,并将其设置为所有行都具有唯一值的字段(您可以添加一些列,例如 BookPriceId,这将是唯一的)。

    public class BookPriceInfo {
      [DataMember]
      public int BookId { get; set; }
      [DataMember]
      public string Name {get; set; }
      [DataMember]
      public string StoreName {get; set;}
      [DataMember]
      public decimal Price {get; set;}
      [DataMember]
      [Key]
      public int BookPriceId {get; set;}
   }

查询结果:

BookPriceId | BookId | Name | StoreName | Price 
1 | 1 | book1 | store1 | 70.00
2 | 1 | book1 | store2 | 69.99
3 | 2 | book2 | store1 | 40.00
4 | 2 | book2 | store2 | 39.99

之后您应该看到查询返回的所有行。
希望这有帮助:)

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:

    public class BookPriceInfo {
      [DataMember]
      [Key]
      public int BookId { get; set; }
      [DataMember]
      public string Name {get; set; }
      [DataMember]
      public string StoreName {get; set;}
      [DataMember]
      public decimal Price {get; set;}
   }

And if you have query result returned from database :

BookId | Name | StoreName | Price 
1 | book1 | store1 | 70.00
1 | book1 | store2 | 69.99
2 | book2 | store1 | 40.00
2 | book2 | store2 | 39.99

Then DataGrig will show only this :

BookId | Name | StoreName | Price 
1 | book1 | store1 | 70.00  
2 | book2 | store1 | 40.00

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

    public class BookPriceInfo {
      [DataMember]
      public int BookId { get; set; }
      [DataMember]
      public string Name {get; set; }
      [DataMember]
      public string StoreName {get; set;}
      [DataMember]
      public decimal Price {get; set;}
      [DataMember]
      [Key]
      public int BookPriceId {get; set;}
   }

Query result:

BookPriceId | BookId | Name | StoreName | Price 
1 | 1 | book1 | store1 | 70.00
2 | 1 | book1 | store2 | 69.99
3 | 2 | book2 | store1 | 40.00
4 | 2 | book2 | store2 | 39.99

After that you should see all rows returned by query.
Hope this helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文