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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:56:33+00:00 2026-05-13T12:56:33+00:00

Question 1: I am playing around with EF4 and I have a model class

  • 0

Question 1: I am playing around with EF4 and I have a model class like :

public class Candidate {

public int Id {get;set;}
public string FullName {get;set;}
public Gender Sex {get;set;}
public EducationLevel HighestDegreeType {get;set;}
}

Here Gender and EducationLevel are Enums like:

public enum Gender {Male,Female,Undisclosed}
public enum EducationLevel {HighSchool,Bachelors,Masters,Doctorate}

How do I get the Candidate Class and Gender and EducationLevel working with EF4 if:

  • I do model first development
  • I do db first development

Edit: Moved question related to object context to another question here.

  • 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-13T12:56:33+00:00Added an answer on May 13, 2026 at 12:56 pm

    Apparently int <-> enum won’t be supported in the initial release of EF4. I agree with those who say this sucks.

    I am using a property that does the casting for me

    public partial class MyEntity
    {
      public MyEnum HurrEnum {get{return (MyEnum)Hurr;} set{Hurr = (int)value;}}
    }
    

    It doesn’t look so bad if you name stuff “correctly” (which means, so it doesn’t look stupid). For instance, I have a ReasonCode enum that’s stored as a Reason in the database, so I have Reason and ReasonCode versions of the property. Works out well enough, for now.


    First, I’m just starting to use EF4 so I’m not intimate with how it works. I assume its similar to L2S but with better entity support. Take this with a grain of salt.

    To be clear, this property is for convenience and I’m 90% sure EF will react badly if you try to query the database using this property. EF doesn’t know about your property and cannot use it to construct sql. So this:

    var foo = from x in Db.Foos where x.HurrEnum == Hurr.Durr select x;
    

    will probably fail to behave as expected where this:

    var foo = Db.Foos.Where(x=> x.HurrEnum == Hurr.Durr);
    

    probably will result in the entire Foos table being brought into memory and then parsed. This property is for convenience and should be used only after the database has been hit! Such as:

     // this is executed in the sql server
     var foo = Db.Foos.Where(x=> x.Hurr == 1 || x.Hurr == 2).ToArray();
     // this is then done in memory
     var hurrFoos = foo.Where(x=> x.HurrEnum == Hurr.Durr);
    

    If you don’t understand the difference is here then you’re playing with fire. You need to learn how EF/L2S interprets your code and converts it into sql statements.

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

Sidebar

Related Questions

I have been playing around with jqgrid, and have the following question. To get
I'm new in Android development and I have the next question/problem. I'm playing around
I'm new in Android development and I have the next question/problem. I'm playing around
I have a quick question. I've been playing around with bit manipulation in c/c++
Hi I am playing around with shapes and canvas and I have a question:
I have a question I really want answered. I have been playing around with
I'm playing around with RhinoCommons and NHibernate and I had a question about the
might be a silly question nonetheless: I'm playing around with the following code: $a='a';
I'm playing around in Scala to try and get the hang of it, so
I just started playing around with Unicorn and NGINX set up (any full-blown reference

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.