New Posts New Posts RSS Feed: Simple Query
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Simple Query

 Post Reply Post Reply
Author
cuneytgargin View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Feb-2008
Location: Turkey
Posts: 13
Post Options Post Options   Quote cuneytgargin Quote  Post ReplyReply Direct Link To This Post Topic: Simple Query
    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 ?

Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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");
  }
}
 
Back to Top
cuneytgargin View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Feb-2008
Location: Turkey
Posts: 13
Post Options Post Options   Quote cuneytgargin Quote  Post ReplyReply Direct Link To This Post 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 ?

Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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");
      }
    }
  }
});


Edited by sbelini - 17-Mar-2011 at 9:04am
Back to Top
cuneytgargin View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Feb-2008
Location: Turkey
Posts: 13
Post Options Post Options   Quote cuneytgargin Quote  Post ReplyReply Direct Link To This Post Posted: 18-Mar-2011 at 2:51am
this time it worked without any error message showing ...
i did not understand why..
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down