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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:08:26+00:00 2026-06-11T15:08:26+00:00

Im new to Entity framework 5 and Im trying the enum support but Im

  • 0

Im new to Entity framework 5 and Im trying the enum support but Im having some problems with it. Im using EF5 as I used the previous versions, this is to create the database and generate the model from the database and use code generation. So, I change the code generation property of the model to “default” and I remove the .tt files.

I have a solution with multiple dlls, one of them has the DataModel (edmx) and another one has an enum called “EnumGender” which has 2 values: male and female.

In the db I have a table Users which has a field called “Gender” (smallint) and im trying to use the “EnumGender” for it.

EnumGender is in a namespace called “Sample.Datatypes.Enums”, so in the edmx model browser im trying to add a Enum. For this I set “EnumGender” as the name, I didnt add any value and I checked the checkbox “Reference external type” and I entered “Sample.Datatypes.Enums.EnumGender” in the textbox.

The problem is that it seems that EF is creating a new enum in the data model namespace, which I dont want, I would like to use EnumGender in the “Sample.Datatypes.Enums” namespace. Also the new enum that the EF creates has no values… If I enter to the datamodel cs file (the code generated) this is what it added:

/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEnumTypeAttribute(NamespaceName="SampleModel", Name="EnumGender")]
[DataContractAttribute()]
public enum EnumGender : short
{
}

I have no clue of what is happening… maybe I cant use a datatype from an external dll… But for what I read about the enums support I should be able to do this…

I would really appreciate it if you can help me with this issue.

Thanks!
Juan

  • 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-11T15:08:27+00:00Added an answer on June 11, 2026 at 3:08 pm

    Though not obvious, but this is by design. The EntityObject template (the one used when you set code generation property of the model to “default”) doesn’t use external types because it requires the types to have certain attributes on them (EdmEnumTypeAttribute and DataContractAttribute for enums). This constraint can only be reliably satisfied if the type itself is also generated by the template.

    I would highly recommend using the DbContext template (the .tt files that were added by default) as it uses POCO types and thus supports external types.

    However if your scenario absolutely requires you to use the EntityObject template there’s a way to change it to use the external enum type:

    1. Make sure that your enum type has the same attributes as the generated one. (Yes, it means that it can’t be shared with a different entity model that uses EnityObject generation)
    2. Download and install the EF 5.x EntityObject T4 template: http://visualstudiogallery.msdn.microsoft.com/1da40393-b5ec-404a-a000-6a7e6e911339
      If you are working on a web project then use this one instead: http://visualstudiogallery.msdn.microsoft.com/94b48556-fcf0-4b9b-8615-20f9066ae9ac
    3. Right-click anywhere in the entity designer view of your model and select “Add Code Generation Item…”
    4. Add “EF 5.x EntityObject Generator”
    5. Open the .tt file that was added
    6. Search for public string SourceCsdlPath{ get; set; } and add this line before it:
    private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName";
    

    7. Search for GetSourceSchemaTypes<EnumType>().OrderBy(c => c.Name) and replace it with:

    GetSourceSchemaTypes<EnumType>()
        .Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName))
        .OrderBy(c => c.Name)
    

    8. Search for string typeName = MultiSchemaEscape(usage.EdmType, code);
    and replace it with:

    string typeName = code.Escape(usage.EdmType.MetadataProperties
                              .Where(p => p.Name == ExternalTypeNameAttributeName)
                              .Select(p => (string)p.Value)
                              .FirstOrDefault())
            ?? MultiSchemaEscape(usage.EdmType, code);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert some data in my database using Entity Framework model, but
I'm trying out the new scaffolding features in MVC 3, using Entity Framework Code
I am using Entity Framework 4.3.1 and I am trying to insert a new
The goal: I'm trying to use the new Entity Framework 4.1 DbContext API (using
I'm new to Entity Framework and am using Database First. I have inherited a
I have created a new application using Entity Framework 4.3 database migrations. The migrations
I am writing a new application using the Entity Framework. Where would the EF
I am new to entity framework and I am trying to go the Code
I am using Entity Framework 4.0 and trying to use the Contains function of
I've been trying to implement POCO over WCF (using Entity Framework 4.0) - just

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.