I am in the process of migrating some old legacy database/code to Microsoft Entity Framework version 6 and have come across the following problem.
The code-behind defines an enumeration and a POCO object as follows:
public enum AssetOwner {
User = 1,
Customer = 2,
Supplier = 3
}
public class Asset {
public int AssetId { get; set; }
public string Reference { get; set; }
public AssetOwner Owner { get; set; }
...
};
In itself, this is fine, but the SQL table uses, for historical reasons I assume, the enum name rather than its value to store the data.
create table [dbo].[Asset]
(
[AssetId] int not null,
[Reference] nvarchar(50) not null,
[Owner] nvarchar(20) not null
...
);
So the table might look like this:
1, 'asset-1', 'Customer'
2, 'asset-2', 'Supplier'
Is there a way (I'm using EF Fluent Configurations) to be able to map the enum's name to the database column?