Reputation: 17065
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
}
};
Upvotes: 0
Views: 1729
Reputation: 17065
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
}
}
Upvotes: 2