Print Page | Close Window

Simple Query

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=2561
Printed Date: 29-Jul-2026 at 5:01pm


Topic: Simple Query
Posted By: cuneytgargin
Subject: Simple Query
Date Posted: 16-Mar-2011 at 1:33am
Hi...
I am checking ideablade 6.8
i have a SL project with ideablade sl template.

in my source
mWebUsers = new ObservableCollection<WebUser>();
var mgr = new Ax5Ent();
var query = mgr.WebUsers;
           
query.ExecuteAsync(op => op.Results.ForEach(mWebUsers.Add));


runs well ....
but
            var query2 = mgr.WebUsers.Where(c => c.username == "cg");
           
            foreach (WebUser auser in query2)
                if (auser.password == "cg")
                    MessageBox.Show("OK");
                else
                    MessageBox.Show("NOTOK");        

when i use upper code clock
query2 returns no result ...
why ?




Replies:
Posted By: sbelini
Date Posted: 16-Mar-2011 at 3:26am
Hi cuneytgargin,
 
query2 is an IEntityQuery<WebUsers> and not a collection with the expected results.
 
You need to execute the query and iterate thru its results.
 
i.e.
var query2 = mgr.WebUsers.Where(c => c.username == "cg");
           
query.ExecuteAsync(op => {
  foreach (WebUser auser in op.Results) {
    if (auser.password == "cg") {
      MessageBox.Show("OK");
    } else {
      MessageBox.Show("NOTOK");
    }
  }
});
 
 
 
or, if running synchronously:
 
var query2 = mgr.WebUsers.Where(c => c.username == "cg");
var results = query2.Execute();
foreach (WebUser auser in results) {
  if (auser.password == "cg") {
    MessageBox.Show("OK");
  } else {
    MessageBox.Show("NOTOK");
  }
}
 


Posted By: cuneytgargin
Date Posted: 17-Mar-2011 at 6:08am
i tried your solution,
query seems to run.. but results don't bring any values.. but i know there is a username with "cg"
even i tried
var query2 = mgr.WebUsers;

it does not gather any data..
strange...


btw my sqlserver is on an instance
does it make any difference ?

any more comments ?



Posted By: sbelini
Date Posted: 17-Mar-2011 at 8:37am
Just to be sure, you are executing the query asynchronously, right? ( I put an sync snippet there, but in this case - SL app - you should be executing the query async first, unless you already have the entities in cache)
 
Also, have you tried checking for errors?
i.e.
var query2 = mgr.WebUsers.Where(c => c.username == "cg");
           
query.ExecuteAsync(op => {
  if (op.HasError) {
    MessageBox.Show(op.Error.Message)
  } else {
    foreach (WebUser auser in op.Results) {
      if (auser.password == "cg") {
        MessageBox.Show("OK");
      } else {
        MessageBox.Show("NOTOK");
      }
    }
  }
});


Posted By: cuneytgargin
Date Posted: 18-Mar-2011 at 2:51am
this time it worked without any error message showing ...
i did not understand why..


Posted By: sbelini
Date Posted: 18-Mar-2011 at 9:35am
Maybe I didn't explain clearly initially.
 
In silverlight apps you can only access the datasource asynchronously.
 
If you try to execute a query synchronously, it might thrown an error, or (if you have set so) it will run against the cache only.
 
var query1 = mgr.Employees;
query1.ExecuteAsync(); // Ok in silverlight
query1.Execute(); // not ok in SL
 
var query2 = query1.With(QueryStrategy.CacheOnly);
query2.Execute(); // Ok in Silverlight - CacheOnly query



Print Page | Close Window