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 3316860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:31:08+00:00 2026-05-17T22:31:08+00:00

I have an IQueryable whose Entity Framework 4 objects I would like to project

  • 0

I have an IQueryable whose Entity Framework 4 objects I would like to project to their DTO equivalents. One such object ‘Person’ is an EF4 class, and the corresponding POCO PersonP is a class I’ve defined. I am using Automapper to map between them. However, when I try the following code:

IQueryable<Person> originalModel = _repo.QueryAll();
IQueryable<PersonP> projection = originalModel.Select(e => Mapper.Map<Person, PersonP>(e));

The projection generates this error at runtime:

LINQ to Entities does not recognize the method 'TestSite.Models.PersonP Map[Person,PersonP](TestSite.DataLayer.Model.Person)' method, and this method cannot be translated into a store expression.

What is the appropriate syntax to create a IQueryable<PersonP> projection using Automapper? Thank you.

P.S. Automapper is configured correctly – I use it in other places to convert back and forth between Person and PersonP, i.e. Mapper.Map<Person, PersonP>(myPersonObject) correctly returns a PersonP object.

EDIT (more code):

I’m using this for a helper function to bind EF4 Entity POCOs (PersonP) to a Telerik Grid – which will not serialize the entities themselves properly since they contain circular references (i.e. navigation properties). My code looks like this:

public static GridModel GetGridModel<TEntity, TPoco>(IRepository<TEntity> repo, GridState gridState) where TEntity : EntityObject
{
 var originalModel = repo.QueryAll().ToGridModel(gridState);
 var projection = originalModel.Select(e => Mapper.Map<TEntity, TPoco>(e));


 return projection.ToGridModel(gridState); // applies filters, sorts, pages, etc...
}

the .ToGridModel method is an extension method on IQueryable and it returns a complex object which I cannot reliably parse – so this leads me to believe I have to perform the filtering after I’ve done the projection to POCOs.

UPDATE 2:

Trying to simplify things, I made a non-generic method like this:

public static GridModel GetGridModel2(IRepository<Client> repo, GridState gridState)
{
 IQueryable<Client> originalModel = repo.QueryAll();
 IQueryable<ClientP> projection = originalModel.Select(c => ClientToClientP(c));

 return projection.ToGridModel(gridState);
}

private static ClientP ClientToClientP(Client c)
{
 return new ClientP { Id = c.Id, FirstName = c.FirstName };
}

This code also fails when creating the projection. I notice that IQueryable.Select() has multiple overloads: Expression> being one of them. Could I represent this function/delegate call using one of these overloads?

  • 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-17T22:31:09+00:00Added an answer on May 17, 2026 at 10:31 pm

    What is the appropriate syntax to create a IQueryable projection using Automapper?

    There isn’t one. Automapper doesn’t do this. It’s the wrong tool for this job.

    One could create an Automapper-like tool to do a similar thing for query projections. I’ve considered it in the past, but always concluded that code using it would be less readable than the projection. I don’t want to optimize code-writing time over code-reading time.

    Your updated code doesn’t work because it isn’t an expression. If you do:

    private static Expression<Func<Client, ClientP>> ClientP ClientToClientP()
    {
        return c => new ClientP { Id = c.Id, FirstName = c.FirstName };
    }
    

    …and then:

    IQueryable<Client> originalModel = repo.QueryAll();
    Expression<Func<Client, ClientP>> exp = ClientToClientP();
    IQueryable<ClientP> projection = originalModel.Select(exp);
    

    …then it will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of objects (IQueryable). Each object has various properties, some string
I have IQueryable list of objects of type T which I want to transform
I have an IQueryable and an object of type T. I want to do
I have an List and I'd like to wrap it into an IQueryable. Is
I have IQueryable<> object. I want to Convert it into List<> with selected columns
I have a domain service, derived from LinqToEntitiesDomainService<FOOEntities> It has one method, IQueryable<Bar> GetBar().
I have three tables that I would like to query: Streams, Entries, and FieldInstances.
I have a method that takes an IQueryable. Is there a LINQ query that
i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from
Have been looking at the MVC storefront and see that IQueryable is returned from

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.