Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3846464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:24:07+00:00 2026-05-19T16:24:07+00:00

In many cases, I want to do some filtering (and sometimes projection) on the

  • 0

In many cases, I want to do some filtering (and sometimes projection) on the server side and then switch to client-side for operations that the LINQ provider doesn’t natively support.

The naive approach (which is basically what I do now) is to just break it up into multiple queries, similar to:

var fromServer = from t in context.Table
                 where t.Col1 = 123
                 where t.Col2 = "blah"
                 select t;

var clientSide = from t in fromServer.AsEnumerable()
                 where t.Col3.Split('/').Last() == "whatever"
                 select t.Col4;

However, there are many times where this is more code/trouble than it’s really worth. I’d really like to do a ‘switch to client side’ in the middle. I’ve tried various methods of using a query continuation, but after doing a ‘select t into foo’ at the end of the first query, foo is still an individual item, not the collection, so I can’t AsEnumerable() it.

My goal is to be able write something more like:

var results = from t in context.Table
              where t.Col1 = 123
              where t.Col2 = "blah"
              // Magic happens here to switch to the client side
              where t.Col3.Split('/').Last() == "whatever"
              select t.Col4;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:24:07+00:00Added an answer on May 19, 2026 at 4:24 pm

    Okay, firstly you absolutely should not use the code here. It was written by trained stunt-hamsters who have been trained not to throw up when dealing with this code of this nature.

    You should absolutely pick one of the options you know about:

    • Use a “temporary” variable (if you can statically type that variable as IEnumerable<T> then you don’t need the call to AsEnumerable – that won’t work if you’ve got an anonymous type as the element type of course)
    • Use brackets for a call to AsEnumerable
    • Use the “fluent” or “dot notation” syntax to make the AsEnumerable call fit in.

    However, you can do a bit of magic, using the way that query expressions are translated. You just need to make one of the standard query operators with a representation in query expressions have a different translation. The simplest option here is probably “Where”. Just write your own extension method taking an IQueryable<T> and a Func<T, SomeType> where SomeType isn’t bool, and you’re away. Here’s an example, first of the hack itself and then a sample use of it…

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    
    public static class QueryHacks
    {
        public static readonly HackToken TransferToClient = HackToken.Instance;
    
        public static IEnumerable<T> Where<T>(
            this IQueryable<T> source,
            Func<T, HackToken> ignored)
        {
            // Just like AsEnumerable... we're just changing the compile-time
            // type, effectively.
            return source;
        }
    
        // This class only really exists to make sure we don't *accidentally* use
        // the hack above.
        public class HackToken
        {
            internal static readonly HackToken Instance = new HackToken();
            private HackToken() {}
        }
    }
    
    public class Test
    {
        static void Main()
        {
            // Pretend this is really a db context or whatever
            IQueryable<string> source = new string[0].AsQueryable();
    
            var query = from x in source
                        where x.StartsWith("Foo") // Queryable.Where
                        where QueryHacks.TransferToClient
                        where x.GetHashCode() == 5 // Enumerable.Where
                        select x.Length;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JavaScript that can appear on many different pages. Sometimes those pages
I'm using c#. In many cases I'm writing code that can benefit from a
After many cases of trial and error, I have concluded that the only solution
I have some old Haskell code that includes QuickCheck test cases. Newer versions of
I know there are many cases which are good cases to use multi-thread in
First of all, there are many cases where Sleep() is misused , for example
In Python scripts, there are many cases where a keyboard interrupt (Ctrl-C) fails to
I'd like to use properties for my instance variables, but in many cases, I
In many prototype scripting cases, it's easier to just stick every form item (such
In most of the methods I use that return some kind of collection I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.