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

  • Home
  • SEARCH
  • 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 538963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:05:12+00:00 2026-05-13T10:05:12+00:00

Consider the following expression: from p in db.People select new Person { Name =

  • 0

Consider the following expression:

from p in db.People
    select new Person {
        Name = p.Name, Age = p.Age, Gender = p.Gender.ToEnum<Gender>()
};

It works to the point of calling extension method static T ToEnum<T>(this string value); as expected.
I understand why there is do not know how to translate string to enum error.
Question is: how do I work around this without introducing another class?
I mean that I could define class PersonWithGenderAsText and then translate that into Person class, but I feel there got to be an easier way.
Specifically, I don’t mind calling .ToList() on the result of the expression above, but I cant figure out the rest.

  • 1 1 Answer
  • 1 View
  • 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-13T10:05:12+00:00Added an answer on May 13, 2026 at 10:05 am

    Just use an anonymous inner type to fetch just the bits you want from the database, use AsEnumerable to switch to “in process” mode, and then you can do the transformation into a Person object:

    var query = db.People
                  .Select(p => new { p.Name, p.Age, p.Gender } )
                  .AsEnumerable()
                  .Select(p => new Person { Name = p.Name,
                                            Age = p.Age,
                                            Gender = p.Gender.ToEnum<Gender>() } );
    

    If there’s no more data in db.People you could simplify this further:

    var query = db.People
                  .AsEnumerable()
                  .Select(p => new Person { Name = p.Name,
                                            Age = p.Age,
                                            Gender = p.Gender.ToEnum<Gender>() } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: Class Demo { Person person = new Person(foo); // assume
Consider the following query: INSERT INTO statement_line_items SELECT count(*)::integer as clicks, sum(amount_cents)::integer as amount_cents,
Consider: <div><a href=http://anirudhagupta.blogspot.com/>Anirudha Web blog</a></div> What is the regular expression to get http://anirudhagupta.blogspot.com/ from
Consider the following code: string propertyName; var dateList = new List<DateTime>() { DateTime.Now };
I am using DBContext API from EF 4.1. Consider following entity model (A, B,
Let's first consider the following expressions in Java. Integer temp = new Integer(1); System.out.println(temp.equals(1));
Consider the following snippet of code: <div align=Left> <font style='font-size:17pt; font-family:Times New Roman;color:#000000;'> <textformat
Consider following make: all: a b a: echo a exit 1 b: echo b
Consider following code: My problem is: 1) I can't seem to cast the errors
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want

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.