2

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」と表示されました

何が悪いのかわからず、それができないようです。それは本当に簡単なはずですが、誰かが私を助けてくれますか

4

2 に答える 2

2

Do not forget than call to RIA services are Asynchronous. Thus the load function return an async result.

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

Then, if you check your itemsSource.count() just after the load call, it will still be 0. But if you wait for the asynchronous result (possibly process it in the callback of the load function), you will see the real results of the request, and it should not be 0 if your request is correct.

于 2013-02-11T08:50:05.483 に答える
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

再度、感謝します...

于 2013-02-12T22:13:53.587 に答える