EF 4.1使用枚举的最佳方法是什么,并能够在列上查询它们?

时间:2011-10-13 08:51:40

标签: c# entity-framework entity-framework-4 entity-framework-4.1

这里我有我的代码,但我想知道这是否会让我对枚举列进行简单的查询。

顺便问一下,您是否看到了我可以在此代码中改进的其他内容?

public class HRContext : DbContext
    {
        public DbSet<Position> Positions { get; set; }
        public DbSet<Applicant> Applicants { get; set; }
        public DbSet<ApplicantImage> ApplicantImages { get; set; }
        public DbSet<ApplicantPosition> ApplicantsPositions { get; set; }
        public DbSet<ApplicationPositionHistory> ApplicationsPositionHistory { get; set; }
    }

    public class HRContextInitializer : DropCreateDatabaseAlways<HRContext>
    {
        protected override void Seed(HRContext context)
        {
        }
    }

    public class Position
    {
        public int id { get; set; }
        public string name { get; set; }
        public int yearsExperienceRequired { get; set; }
    }

    public class Applicant
    {
        public int ApplicantId { get; set; }
        public string name { get; set; }
        public string telephone { get; set; }
        public string skypeuser { get; set; }
        public ApplicantImage photo { get; set; }
    }

    public class ApplicantImage
    {
        public int ApplicantId { get; private set; }
        public byte[] Image { get; set; }
    }

    public class Address
    {
        public string Country { get; set; }
        public string City { get; set; }
        public string AddressLine1 { get; set; }
        public string AddressLine2 { get; set; }    
    }

    public class ApplicantPosition
    {
        public Position appliedPosition { get; set; }
        public Applicant applicant { get; set; }
        public DateTime appliedDate { get; set; }
        public int StatusValue { get; set; }

        public Status Status
        {
            get { return (Status)StatusValue; }
            set { StatusValue = (int)value; }
        }
    }

    public class ApplicationPositionHistory
    {
        public ApplicantPosition applicantPosition { get; set; }
        public Status oldStatus { get; set; }
        public Status newStatus { get; set; }
        public string comments { get; set; }
        public DateTime dateModified { get; set; }
    }

    public enum Status
    {
        Applied,
        AcceptedByHR,
        AcceptedByTechnicalDepartment,
        InterviewedByHR,
        InterviewedByTechnicalDepartment,
        InterviewedByGeneralManager,
        AcceptedByGeneralManager,
        NotAccepted
    }

1 个答案:

答案 0 :(得分:2)

您不能在查询中使用枚举(只能使用June 2011 CTP)。在查询中最接近使用枚举的是使用Enum wrappers