Entity Framework Model-First Enum Type MetadataType

I know that when working with the first model development, you can use the partial classes generated by the t4 templates to add metadata. eg.

public partial class Address
{        
    public int Id { get; set; }
    public string Street1 { get; set; }
    public string Street2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
}

Then in a separate file I:

[MetadataType(typeof(AddressMetadata))]
public partial class Address {
}

internal sealed class AddressMetadata {

    [Display(Name = "Street")]
    public string Street1 { get; set; }

    [Display(Name = "Street (cont.)")]
    public string Street2 { get; set; }

    [Display(Name = "Zip code")]
    public string Zip { get; set; }
}

I am trying to do this for the type of enumeration defined in the EDMX file.

// this doesn't work
[MetadataType(typeof(ContactTypeMetadata))]
public enum ContactType {

}

public class ContactTypeMetadata {
}

By doing this, I get the following error:

Error   1   The namespace 'Models' already contains a definition for 'ContactType'

Is it necessary in any case to perform the same functions for enumerations as for classes in a project with the first model?

EDIT

In the EDMX file, I defined the type of enumeration:

namespace WindowsFormsApplication1
{
    using System;

    public enum ContactType : int
    {
        CEO = 0,
        CIO = 1,
        Peasant = 2
    }
}

I am trying to find a way using a similar mechanism (in separate files so that if I change EDMX, my changes will not be overwritten) to accomplish this:

namespace WindowsFormsApplication1
{
    using System;

    public enum ContactType : int
    {
        [Display(Name="Chief Executive Officer")]
        CEO = 0,

        [Display(Name="Chief Information Officer")]
        CIO = 1,

        [Display(Name="Regular Employee")]
        Peasant = 2
    }
}
+4
1

. , .

enum .edmx. . ContactType.cs , , , , , .

enmx enum, , ContactType.cs, .

ContactType

using System;
namespace YourEnumNamespace
{
    public enum ContactType : int
    {
        [Display(Name="Chief Executive Officer")]
        CEO = 0,

        [Display(Name="Chief Information Officer")]
        CIO = 1,

        [Display(Name="Regular Employee")]
        Peasant = 2
    }
}

.edmx- URL- ContactType, " ", .

Model browser

Solution Browse, edmx - " ", "Enum Type".

Add New Enum Type

, ContactType Reference External type, enum, , . . YourEnumNamespace.ContactType.

edmx edmx.

New enum

, edmx , , , , MyContactTypeProperty

Entity with Property

.

enum property

. , .., . , , . !

+10

All Articles