簡體   English   中英

Silverlight WCF RIA服務。 檢查布爾方法的結果

[英]Silverlight WCF RIA Services. Check result of a boolean method

Silverlight應用程序使用WCF RIA服務連接到SQL Server數據庫。 在將一堆新記錄插入表中之前,我應檢查該表是否包含其中一個字段中具有特定值的任何記錄。

我在Domain服務類中的服務器端方法:

    [Invoke]
    public bool CheckRec(string nameFilter)
    {
        bool res = false;
        if (this.ObjectContext.MyTest.FirstOrDefault(p => p.Name == nameFilter) != null)
        {
            res = true;
        }            
        return res;
    }

如何在客戶端上檢查方法結果? 我正在嘗試以下方式,但需要一些幫助才能正確實現:

MyTestContext testcontext = new MyTestContext();
string tname =  savetdlg.TNameTBox.Text;
testcontext.CheckRec(tname).Completed += (df, fg) => 
                {
                    bool notunique = ?????? // how to get result of the method?
                    if (notunique == true)
                    {
                        //todo if record exists
                    }
                    else
                    {
                        //todo if record doesn't exist
                    }                   
                };

好吧,可以通過以下方式完成:

MyTestContext testcontext = new MyTestContext();
string tname =  savetdlg.TNameTBox.Text;

testcontext.CheckRec(tname, context_CheckRecCompleted, null);

void context_CheckRecCompleted(InvokeOperation<bool> op)
    {
        bool notunique = op.Value;
        if (notunique == true)
        {
            //todo if record exists
        }
        else
        {
            //todo if record doesn't exist
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM