How to convert an IQueryable<T> to an IRavenQueryable<T> ?

237 views
Skip to first unread message

Justin A

unread,
May 16, 2016, 12:46:31 AM5/16/16
to RavenDB - 2nd generation document database
Hi :)

I usually do linq filters to make my code a bit readble. This returns an IQueryably<T> .. so when I wish to do something like an .Include .. it doesn't work because of unable to implicit covnert.

Is there a trick I'm missing?

for example:

(pseduo codeish)

    public static class InviteFilters
    {
        public static IQueryable<Invite> WithToken(this IQueryable<Invite> value,
                                                   string token)
        {
            token.ShouldNotBeNullOrWhiteSpace();

            return value.Where(x => x.Token == token);
        }
    }

...

var invite = session.Query<Invite>()
                    .WithToken(someToken)
                    .Include(x => x.CreatedByUserId)
                    .SingleAsync();

So here, you can see i'm trying to load an Invite based upon a Token and then include the user who made this invite. Ok, sweet. But I can't because Include expects an IRavenQueryable while my filter returns a normal IQueryable.

Thoughts please?


-me-

Oren Eini (Ayende Rahien)

unread,
May 16, 2016, 1:46:09 AM5/16/16
to ravendb
You can cast it, or change you method to accept and return IRavenQueryable

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin A

unread,
May 16, 2016, 2:04:42 AM5/16/16
to RavenDB - 2nd generation document database
do you mean with an explicit cast =>((IRavenQueryable)myQueryable).Include.... ?

Oren Eini (Ayende Rahien)

unread,
May 16, 2016, 3:33:30 AM5/16/16
to ravendb
        public static IRavenQueryable<Invite> WithToken(this IRavenQueryable<<Invite> value,


Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Mon, May 16, 2016 at 9:04 AM, Justin A <jus...@adler.com.au> wrote:
do you mean with an explicit cast =>((IRavenQueryable)myQueryable).Include.... ?

--

Justin A

unread,
May 16, 2016, 4:51:49 AM5/16/16
to RavenDB - 2nd generation document database
Ah - soz. I forgot to mention, I don't want to change the filter because that would mean the filters take a dependency on RavenDb.Client, etc.

Daniel Häfele

unread,
May 16, 2016, 5:22:27 AM5/16/16
to RavenDB - 2nd generation document database
But in that use-case you already have a dependency on RavenDB, right?
Maybe you want a RavenDB queryable wrapper extension method for your original one?

public static class InviteRavenFilters
{
   
public static IRavenQueryable<Invite> WithToken(this IRavenQueryable<Invite> value, string token)
   
{
       
return (IRavenQueryable<Invite>)value.WithToken(token);
   
}
}


Reply all
Reply to author
Forward
0 new messages