Silverlight WCF RIA 服务。检查布尔方法的结果

发布于 2024-10-04 02:41:01 字数 1025 浏览 0 评论 0原文

Silverlight 应用程序使用 WCF RIA 服务连接到 SQL Server 数据库。在将一堆新记录插入表中之前,我应该检查该表是否包含某个字段中具有特定值的任何记录。

我在域服务类中的服务器端方法:

    [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
                    }                   
                };

A Silverlight application uses WCF RIA Services for connection to a SQL Server database. Before inserting a bunch of new records into a table, I should check if this table contains any records with a certain value in one of the fields.

My server side method in Domain service class:

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

How I could check the method result on the client?
I'm trying the way like the following, but need some help to implement this correctly:

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
                    }                   
                };

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

寄意 2024-10-11 02:41:01

嗯,通过以下方式完成:

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
        }
    }

Well, done in the following way:

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