New Posts New Posts RSS Feed: Silverlight: Using the Any() method
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Silverlight: Using the Any() method

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

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Topic: Silverlight: Using the Any() method
    Posted: 22-Mar-2011 at 9:33am
Good Afternoon,
 
I'm wondering whether or not IdeaBlade supports (with the latest version) the Any() method in Silverlight, and if so, what's wrong with this statement. What I'm trying to do is to return a list of objects (Classes) that that a Section that begins on a certain day.
Some of the documentation with DevForce says that .Any wasn't supported because it returns a scalar value, but this really is part of a sub-query.
 
Query:
 

var query = objEntityManager.Classes

                .Include("Sections")

                .OrderBy(op => op.ClassName)

                .Where(op => (this.IsFilterByBeginDate != true || false ||op.Sections.Any((cs,i) => (cs.BeginClassDateTime.Date == DateTime.Now.Date))));

 
The Error returned is:
LINQ to Entities does not recognize the method "Boolean Any[Sections]..... method cannot be translated into a store expression."
 
 
Any thoughts?

 

Back to Top
jipock View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Posted: 22-Mar-2011 at 9:44am
Quick Note - the " || false " in the where clause is in there by accident. (It was left over scaffolding from debugging).
 
It should read:
 
.Where(op => (this.IsFilterByBeginDate != true || op.Sections.Any((cs,i) => (cs.BeginClassDateTime.Date == DateTime.Now.Date))));
 
Sorry about confusion.
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: 23-Mar-2011 at 10:32am

Hi Jipock,

 

Unfortunately, the Entity Framework does not support Any(Func<T, int, bool>) so you can only execute it against the cache (in either in SL and/or WPF).  

However, your query doesn't really need Any(Func<T, int, bool>), and you could simply use Any(Func<T, bool>) as it is supported by EF and you can run against the query.

So, you query slightly modified:

 

var query = objEntityManager.Classes

                .Include("Sections")

                .OrderBy(op => op.ClassName)

                .Where(op => (this.IsFilterByBeginDate != true || op.Sections.Any(cs => cs.BeginClassDateTime.Date == DateTime.Now.Date)));

 

would execute properly.

We will add a note in our documentation explaining this.

 

Regards,

    Silvio.

 

Back to Top
jipock View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Posted: 29-Mar-2011 at 12:47pm
I just tried the code you mentioned, however, the code does not compile. It says there was no method of .Any that accepts one argument.
 
Is this an Extension method in another DLL?
 
 
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: 29-Mar-2011 at 3:08pm
You will only need System.Linq and IdeaBlade.EntityModel.
 
I have attached is a simple Silverlight sample against NorthwindIB running a similar query as provided before.
 
 
Silvio.
Back to Top
jipock View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Dec-2010
Location: Cherry Hill, NJ
Posts: 39
Post Options Post Options   Quote jipock Quote  Post ReplyReply Direct Link To This Post Posted: 05-Apr-2011 at 5:30am
Got it -
 
I was simply missing "using System.Linq;" as a declaration....
 
Gotta love overloaded functions in different namespaces..
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down