I am looking for a better way to structure my application so that I can work with enums using entity framework, and cases where I would need to use TSQL eg stored procs ,common table expressions etc.It looks great to use it on the linq to Entities side , but on the TSQL side it does not look that nice eg when projecting the results and you want the enum string values.I have already looked at the EF enum support tutorial here and other examples from the web and on SO and I just cant seem to find a standard way
Part of the code from the tutorial here
public enum DepartmentNames
{
English,
Math,
Economics
}
public partial class Department
{
public int DepartmentID { get; set; }
public DepartmentNames Name { get; set; }
public decimal Budget { get; set; }
}
My list of questions are:
- how to deal with enums in case of stored procs or common table expressions, or anything requiring TSQL, rather than linq to Entities
- suppose I create a class for EF to store the enum values,is it best practice to have an equivalent table in my database for the enum, by creating an equivalent class like in the code below, and manualy adding the State1 ,State2 values in the EF seeding process etc.
- following above ,what is the best way to name + structure the enum ,like you can see from the code
for example
public class SomeStateType
{
public int SomeStateTypeId { get; set; }
public string Name { get; set; }
public enum Type
{
State1 = 1,
State2 = 2,
}
}