.Net Silverlight WCF RIA查询项目计数

时间:2013-02-10 20:52:16

标签: vb.net silverlight wcf-ria-services

我在Silverlight应用程序中检索项目计数时遇到问题,使用以下代码填充包含sql项目的组合框:

  objctx = New BanksDomain
        Dim itemType = NameComboBox.SelectedItem.[GetType]()
        Dim pi = itemType.GetProperty(NameComboBox.DisplayMemberPath)
        Dim cbi = pi.GetValue(NameComboBox.SelectedItem, Nothing).ToString()
        Dim BankName As String = cbi

        Dim query As EntityQuery(Of Branches) = objctx.GetBranchesByBankQuery(BankName)
        query.IncludeTotalCount = True
        Dim loadOp As LoadOperation(Of Branches) = Me.objctx.Load(query)

        Branch_NameComboBox.ItemsSource = loadOp.Entities

我试过从组合框项目计数得到无效,我试图通过textbox.text = loadop.entities.count加载它,但它显示“0”

我不知道什么是错的,我似乎无法做到,虽然它应该很简单,可能有人帮助我

2 个答案:

答案 0 :(得分:2)

不要忘记调用RIA服务是异步的。因此,load函数返回异步结果。

Dim loadOp As LoadOperation(Of Branches) = Me.objctx.Load(query)
Branch_NameComboBox.ItemsSource = loadOp.Entities

然后,如果您在加载调用后检查itemsSource.count(),它仍将为0。 但是如果你等待异步结果(可能在加载函数的回调中处理它),你将看到请求的真实结果,如果你的请求是正确的,它不应该是0。

答案 1 :(得分:1)

非常感谢伙计,你救了我的命,现在我可以得到数,如果有人有一天需要它,这就是代码:

Dim query As EntityQuery(Of Branches) = objctx.GetBranchesByBankQuery(BankName)
            query.IncludeTotalCount = True
            Dim loadOp As LoadOperation(Of Branches) = Me.objctx.Load(query, New Action(Of LoadOperation(Of Branches))(AddressOf GetBranchesCompleted), True)

Then

Private Sub GetBranchesCompleted(args As LoadOperation(Of Branches))

        Branch_NameComboBox.ItemsSource = args.Entities
        NoOfBTextBlock.Text = args.Entities.Count.ToString


    End Sub

再次感谢...