Skip to content

Query: Consider adding method to force client evaluation of an expression #12736

Closed as not planned

Description

@divega

The fix for #12697 enables using a method defined like this in a query:

public static T Client<T>(T s) => s;

The point being that the method is opaque to our query translator and therefore forces client evaluation. I want to suggest that we consider adding a method like that somewhere under the static EF class for better discoverability.

I haven't tested how well it works and I am not sure I understand all the implications but ideally this could be used both on the way in (to force funcletization of an expression that would otherwise be translated, i.e. a shortcut for having to write the expression outside the query) and on the way out (force client evaluation of an expression that would otherwise be translated).

Example usage:

                var data = (from c in db.Checks
                                 join ct in db.CheckTemplates
                                      .Include(a => a.Implementers).ThenInclude(u => u.User)
                                 on c.CheckTemplateId equals ct.CheckTemplateId
                                 where c.CheckId == checkId
                                 select new
                                 {
                                     CheckId = c.CheckId,
                                     Description = ct.Description,
                                     Implementers = EF.Client(ct).Implementers,
                                     NumExaminers = ct.Examiners.Count
                                 };

Activity

  1. pmiddleton commented on Jul 20, 2018

    @pmiddleton
    Contributor

    Could users misunderstand the feature and try passing a lambda to the Client method that references column data? That won't be executable client side.

  2. divega commented on Jul 20, 2018

    @divega
    ContributorAuthor

    @pmiddleton that is a reason to come up with a good name. Worst case that would cause N+1 queries (or throw).

  3. ajcvickers commented on Jul 30, 2018

    @ajcvickers
    Contributor

    Tracking this as part of 3.0 query behaviors, so added to #12795

  4. added this to the 3.0.0 milestone on Jul 30, 2018
  5. removed this from the 3.0.0 milestone on Jan 23, 2019
  6. removed their assignment
    on Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions