Enum typed properties in Entity Framework objects?

Is there a way to match the generated objects for an enumeration?

And I mean simply:

class Person
{
    RelationshipStaus RelationshipStatus { get; set; }
}

enum RelationshipStatus : byte
{
    Single,
    Married,
    Divorced
}

The RelationshipStatus property in the database is a simple byte, I want this to be an enumeration in my project.

+3
source share
3 answers

Enumerations are supported at EF ≥ 5.

See this .

0
source

Unfortunately, you cannot, at least not directly. For convenience, you can create an accessor that converts the value to and from an enumeration type:

public int RelationshipStatusInt { get; set; }

public RelationshipStatus RelationshipStatus
{
    get { return (RelationshipStatus)RelationshipStatusInt; }
    set { RelationshipStatusInt = (int)value; }
}

Linq EF, DB ( Linq to Objects).

, ...

+4

As Thomas said, there is no solution.

I would just recommend to users who are faced with the desire to use transfers in EF and vote for this connection: http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions / 1015335-support-for-enums

+2
source

Source: https://habr.com/ru/post/1756693/


All Articles