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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:22:10+00:00 2026-06-11T05:22:10+00:00

Can entity framework 5 handle char enums? I have it working with an int,

  • 0

Can entity framework 5 handle char enums? I have it working with an int, but with a char I get the error below where the column in the database is char(1).

The 'Gender' property on 'Division' could not be set to a 'String' value. You must set this property to a non-null value of type 'Gender'.

public enum Gender
{
    Male = 'M',
    Female = 'F'
}
  • 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-11T05:22:12+00:00Added an answer on June 11, 2026 at 5:22 am

    Your enum type is not of char type but of int type. The following line will show you that:

    Console.WriteLine(typeof(Gender).GetEnumUnderlyingType());
    
    System.Int32
    Press any key to continue . . .
    

    The values of your enum members are actually 77 and 70 respectively:

    Console.WriteLine((int)Gender.Male);
    Console.WriteLine((int)Gender.Female);
    
    77
    70
    Press any key to continue . . .
    

    The only valid underlying types of enum types in C#/VB.NET are byte, sbyte, short, ushort, int, uint, long and ulong. If you try putting an underlying type that is not on this list like this:

    public enum Gender : char
    { 
        Male = 'M', 
        Female = 'F' 
    }
    

    You will see the following compilation error:

    error CS1008: Type byte, sbyte, short, ushort, int, uint, long, or ulong expected
    

    This is the theory behind enums in C#. Now the EF part – EF currently suports only the following underlying types for enums: Edm.Byte, Edm.SByte, Edm.Int16, Edm.Int32 and Edm.Int64 (the Edm type system does not have unsigned types). For enums properties the corresponding column in the database must match the underlying type of the enum type of the property (i.e. if your the underlying type of your enum property is Edm.Int32 then the column should be of int type).

    In your case – if you really want to go with your enum type your column in the database should be of int type. You should expect to see values of 70 and 77 in the column when you add entities.

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

Sidebar

Related Questions

Can someone tell me how can I get MS Entity Framework working with PostgreSQL.
In Entity Framework 4.2 I have a Trips entity that can have 0..* PlacesOfInterest
How can I give set foreign key value field in Entity Framework. I have
Can anyone help? I have been using the entity framework and its going well
Trying to map the following schema using the Entity Framework. A Customer can have
I'm trying to get a handle on Entity Framework Performance, specifically around the dynamic
I am have some trouble getting Entity Framework to handle a many to many
I am working with Entity Framework Code first. I have a simple model: public
I am using Entity Framework and have a table of BusinessUnits which can reference
I am using entity framework and I can't find include method like in this

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.