Mapping and executing Expression in IQueryableExpression Versus StatementDynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>What is the difference between IQueryable<T> and IEnumerable<T>?How do you transfer the execution of a Expression created by an IQueryable object to a IEnumerable?Returning IEnumerable<T> vs. IQueryable<T>IQueryable to List<T>using IQueryable deferred executionExecute expression on another IQueryable source“LINQ to Entities does not recognize the method” on IQueryable<T>.WhereAutomapper mapping function

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

I found an audio circuit and I built it just fine, but I find it a bit too quiet. How do I amplify the output so that it is a bit louder?

Will number of steps recorded on FitBit/any fitness tracker add up distance in PokemonGo?

How do you make your own symbol when Detexify fails?

Has any country ever had 2 former presidents in jail simultaneously?

Does the Linux kernel need a file system to run?

How to make money from a browser who sees 5 seconds into the future of any web page?

Biological Blimps: Propulsion

Is it allowed to activate the ability of multiple planeswalkers in a single turn?

C++ copy constructor called at return

Why is the "ls" command showing permissions of files in a FAT32 partition?

A Trivial Diagnosis

Can I say "fingers" when referring to toes?

What kind of floor tile is this?

What does Apple's new App Store requirement mean

Did the UK lift the requirement for registering SIM cards?

How to draw a matrix with arrows in limited space

Can I cause damage to electrical appliances by unplugging them when they are turned on?

Can you use Vicious Mockery to win an argument or gain favours?

Why Shazam when there is already Superman?

What fields between the rationals and the reals allow a good notion of 2D distance?

Delete multiple columns using awk or sed

US tourist/student visa



Mapping and executing Expression in IQueryable


Expression Versus StatementDynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>What is the difference between IQueryable<T> and IEnumerable<T>?How do you transfer the execution of a Expression created by an IQueryable object to a IEnumerable?Returning IEnumerable<T> vs. IQueryable<T>IQueryable to List<T>using IQueryable deferred executionExecute expression on another IQueryable source“LINQ to Entities does not recognize the method” on IQueryable<T>.WhereAutomapper mapping function













0















I want to create a generic method that recieve an Expression<Func<IQueryable<TDTO>, IQueryable<TDTO>>> and map to Expression<Func<IQueryable<TEntity>, IQueryable<TEntity>>>



And then, using EF execute that Expression.



I am using Automapper Expression Translate, to do the mapping between Expressions, but I don't know how to execute that Expression.



Here is how I am mapping the Expressions:



public List<DTO.Category> GetPaged(int page, int pageSize, Expression<Func<IQueryable<DTO.Category>, IQueryable<DTO.Category>>> predicate)

var expression = Mapper.Map<Expression<Func<IQueryable<Category>, IQueryable<Category>>>>(predicate);

return Mapper.Map<List<Category>, List<DTO.Category>>
(
_repository.Paged(page, pageSize, expression).Results.ToList()
);



And then, I have the next Extension Method where I need to execute the Expression:



public static PagedResult<T> GetPaged<T>(this IQueryable<T> query, int page, int pageSize, Expression<Func<IQueryable<T>, IQueryable<T>>> predicate) where T : class

var result = new PagedResult<T>();
result.CurrentPage = page;
result.PageSize = pageSize;
result.RowCount = query.Count();


var pageCount = (double)result.RowCount / pageSize;
result.PageCount = (int)Math.Ceiling(pageCount);

var skip = (page - 1) * pageSize;
result.Results = query.Provider.CreateQuery<T>(predicate).ToList(); -- This is what I tried but it doesn't work

return result;



Please, let me know what I am doing wrong.



Thanks in advance.










share|improve this question


























    0















    I want to create a generic method that recieve an Expression<Func<IQueryable<TDTO>, IQueryable<TDTO>>> and map to Expression<Func<IQueryable<TEntity>, IQueryable<TEntity>>>



    And then, using EF execute that Expression.



    I am using Automapper Expression Translate, to do the mapping between Expressions, but I don't know how to execute that Expression.



    Here is how I am mapping the Expressions:



    public List<DTO.Category> GetPaged(int page, int pageSize, Expression<Func<IQueryable<DTO.Category>, IQueryable<DTO.Category>>> predicate)

    var expression = Mapper.Map<Expression<Func<IQueryable<Category>, IQueryable<Category>>>>(predicate);

    return Mapper.Map<List<Category>, List<DTO.Category>>
    (
    _repository.Paged(page, pageSize, expression).Results.ToList()
    );



    And then, I have the next Extension Method where I need to execute the Expression:



    public static PagedResult<T> GetPaged<T>(this IQueryable<T> query, int page, int pageSize, Expression<Func<IQueryable<T>, IQueryable<T>>> predicate) where T : class

    var result = new PagedResult<T>();
    result.CurrentPage = page;
    result.PageSize = pageSize;
    result.RowCount = query.Count();


    var pageCount = (double)result.RowCount / pageSize;
    result.PageCount = (int)Math.Ceiling(pageCount);

    var skip = (page - 1) * pageSize;
    result.Results = query.Provider.CreateQuery<T>(predicate).ToList(); -- This is what I tried but it doesn't work

    return result;



    Please, let me know what I am doing wrong.



    Thanks in advance.










    share|improve this question
























      0












      0








      0








      I want to create a generic method that recieve an Expression<Func<IQueryable<TDTO>, IQueryable<TDTO>>> and map to Expression<Func<IQueryable<TEntity>, IQueryable<TEntity>>>



      And then, using EF execute that Expression.



      I am using Automapper Expression Translate, to do the mapping between Expressions, but I don't know how to execute that Expression.



      Here is how I am mapping the Expressions:



      public List<DTO.Category> GetPaged(int page, int pageSize, Expression<Func<IQueryable<DTO.Category>, IQueryable<DTO.Category>>> predicate)

      var expression = Mapper.Map<Expression<Func<IQueryable<Category>, IQueryable<Category>>>>(predicate);

      return Mapper.Map<List<Category>, List<DTO.Category>>
      (
      _repository.Paged(page, pageSize, expression).Results.ToList()
      );



      And then, I have the next Extension Method where I need to execute the Expression:



      public static PagedResult<T> GetPaged<T>(this IQueryable<T> query, int page, int pageSize, Expression<Func<IQueryable<T>, IQueryable<T>>> predicate) where T : class

      var result = new PagedResult<T>();
      result.CurrentPage = page;
      result.PageSize = pageSize;
      result.RowCount = query.Count();


      var pageCount = (double)result.RowCount / pageSize;
      result.PageCount = (int)Math.Ceiling(pageCount);

      var skip = (page - 1) * pageSize;
      result.Results = query.Provider.CreateQuery<T>(predicate).ToList(); -- This is what I tried but it doesn't work

      return result;



      Please, let me know what I am doing wrong.



      Thanks in advance.










      share|improve this question














      I want to create a generic method that recieve an Expression<Func<IQueryable<TDTO>, IQueryable<TDTO>>> and map to Expression<Func<IQueryable<TEntity>, IQueryable<TEntity>>>



      And then, using EF execute that Expression.



      I am using Automapper Expression Translate, to do the mapping between Expressions, but I don't know how to execute that Expression.



      Here is how I am mapping the Expressions:



      public List<DTO.Category> GetPaged(int page, int pageSize, Expression<Func<IQueryable<DTO.Category>, IQueryable<DTO.Category>>> predicate)

      var expression = Mapper.Map<Expression<Func<IQueryable<Category>, IQueryable<Category>>>>(predicate);

      return Mapper.Map<List<Category>, List<DTO.Category>>
      (
      _repository.Paged(page, pageSize, expression).Results.ToList()
      );



      And then, I have the next Extension Method where I need to execute the Expression:



      public static PagedResult<T> GetPaged<T>(this IQueryable<T> query, int page, int pageSize, Expression<Func<IQueryable<T>, IQueryable<T>>> predicate) where T : class

      var result = new PagedResult<T>();
      result.CurrentPage = page;
      result.PageSize = pageSize;
      result.RowCount = query.Count();


      var pageCount = (double)result.RowCount / pageSize;
      result.PageCount = (int)Math.Ceiling(pageCount);

      var skip = (page - 1) * pageSize;
      result.Results = query.Provider.CreateQuery<T>(predicate).ToList(); -- This is what I tried but it doesn't work

      return result;



      Please, let me know what I am doing wrong.



      Thanks in advance.







      c# entity-framework expression automapper iqueryable






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 5:01









      enriquesromanenriquesroman

      1014




      1014






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036406%2fmapping-and-executing-expression-in-iqueryablet%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036406%2fmapping-and-executing-expression-in-iqueryablet%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко