Print Page | Close Window

Question about Contains

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3451
Printed Date: 17-Oct-2025 at 8:13pm


Topic: Question about Contains
Posted By: pponzano
Subject: Question about Contains
Date Posted: 24-May-2012 at 1:14am
Hello,
I'm writing my first silverlight application that makes access to the Manager direcly without passing from storedprocedure...
I've got a small issue with the contains...

if I do

var dboard = (sender as RadDataForm).CurrentItem as DBOARD;

var query = repository.Manager.DBOARD.Where(o1 => o1.ID == dboard.ID).AsScalarAsync<DBOARD>();
query.ExecuteAsync(op =>
{
op.Results.Cast<DBOARD>().Count();
repository.Manager.SaveChangesAsync();
});

It works....

if I do var query = repository.Manager.DBOARD.Contain(dboard) it doesn't have the AsScalarAsync and if I run this I got
Queries in Silverlight must be executed asynchronously.

What am I doing wrong?

Thanks



Replies:
Posted By: kimj
Date Posted: 24-May-2012 at 10:53am
The AsScalarAsync extension is used to asynchronously execute what would otherwise be an "immediate execution" query.  These are queries using a .First() or .Sum() or .Contains() or similar operator, which because they will be executed immediately and synchronously, are not allowed in Silverlight.
 
To use .Contains, or .Any, or .Count, which I think would also work in your scenario, you can do something like the following:
   var op = repository.Manager.DBOARD.Select(o1 => o1.ID).AsScalarAsync().Contains(dboard.ID);
or
   var op = repository.Manager.DBOARD.Where(o1 => o1.ID == dboard.ID).AsScalarAsync().Any();
or
   var op = repository.Manager.DBOARD.Where(o1 => o1.ID == dboard.ID).AsScalarAsync().Count();
 
Note that in all cases an EntityScalarQueryOperation is returned, not a query.  This is because the query is still executed immediately.
 
You can read more about AsScalarAsync here - http://drc.ideablade.com/xwiki/bin/view/Documentation/async-immediate-execution - http://drc.ideablade.com/xwiki/bin/view/Documentation/async-immediate-execution
 



Print Page | Close Window