I am fairly new to entity framework and I want to know what is the best approach to assign enumeration field to an object.
I want to write:
myObject.Status = Status.Active;
Shall I do:
myObject.Status = _context.myObjects.First(x=>x.Status.StatusId == Status.ActiveId);
and define
public partial class Status
{
public const int ActiveId = 1;
}
or can I do something like:
public partial class Status
{
public static Status Active = new Status(1, "Active");
}
which works out as
myObject.Status = Status.Active;
Or 3rd option can be just to forgot about mapping status into entity framework and just use Id on domain objects
myObject.StatusId = Status.Active.Id;
Can you let me know what is the best practice or simply what do you prefer yourself?
Thanks