New Posts New Posts RSS Feed: Question about Contains
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Question about Contains

 Post Reply Post Reply
Author
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Topic: Question about Contains
    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.
 
 
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down