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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:34:44+00:00 2026-06-09T21:34:44+00:00

Is there anyway to create a auto projection in entity framework? see please: public

  • 0

Is there anyway to create a auto projection in entity framework? see please:

public class Person{ 
    public int Id {get; set;} 
    public string FirstName {get; set;} 
    public string LastName {get; set;} 
    public string FatherName {get; set;} 
    public string City {get; set;} 
    public string AddressLine {get; set;} 
    public string Something {get; set;} 
}

public class PersonNameModel{
    public string FirstName {get; set;} 
    public string LastName {get; set;} 
    public string FatherName {get; set;} 
}

public class PersonAddressModel{
    public string City {get; set;} 
    public string AddressLine {get; set;} 
}

// etc...

I mean I be able to replace normal projection like:

context.Persons.Select(t => new PersonNameModel{ FirstName = t.FirstName /* etc */ });

whit an extension method that can use reflection and create an auto projection like:

public static class MyExtensions{
    public static IQueryable<T> AutoSelect<T, TProject>(this IQueryable<T> q){
        // read TProject type in reflection
        // create a projection as a IQueryable<T> 
    }
}

Is there any way? I googled it, but didn’t find any resource. Can you guide me please?

  • 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-06-09T21:34:46+00:00Added an answer on June 9, 2026 at 9:34 pm

    Yes, it’s possible to auto project entity framework entities to some Dto. See one of implementations here https://gist.github.com/1367880

    You can use it as:

    context.Persons.Project().To<PersonNameModel>().ToList();
    

    In that case the db query will be generated to select only required columns (specified by PersonNameModel).

    If you want just to map query results (that retrieved objects), so EmitMapper or AutoMapper should be your choice.

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

Sidebar

Related Questions

Is there anyway to auto-create ASP.NET controls at Design time based on fields in
Assume there are two entities with ManyToOne relation: @Entity public class A { private
Is there any way to auto-magically create Class Diagrams from Java code? I am
Is there anyway to create an ObjectSet from a DbSet ? Some background information:
Is there anyway to create a dialog that is modal to a view and
Is there anyway to create C# spelling checker without using Office library? I would
Is there anyway to create a desktop icon (cross platform/browser) from a linked image
Is there anyway I can create nodes out of a string? I've searched the
Is there anyway to get the seed fieldname? What I mean by seed is
is there anyway to invoke the auto row sorter in a jtable that is

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.