Generate Enum from Values present in a table using ADO.NET Entity framework

前端 未结 2 572
清酒与你
清酒与你 2021-01-04 23:02

My requirement is to create an Enum based on values present in a table from DB. I am using ADO.NET Entity Framework model (.edmx file), Can any one of you help me out.

2条回答
  •  隐瞒了意图╮
    2021-01-04 23:33

    Daniel's template is nice and all, but I've put some more effort into such a template so it does all these:

    • generates enumeration values with explicit integer values;
    • uses Visual Studio's namespace naming convention so generated enumerations have project's default namespace with any subfolders appended (just like any code file in Visual Studio);
    • adds complete enumeration XML documentation by using additional description table column values; if you don't have these never mind;
    • correctly names the generated file and adds an additional attribute in the code so the generated enum doesn't get scrutinised by code analysis;
    • multi-word lookup table values are correctly concatenated to pascal-cased equivalents (ie. Multi word value becomes a MultiWordValue);
    • enumeration values always start with a letter;
    • all enumeration values consist of only letters and numbers, everything else gets cut out;

    Anyway. Everything is very well documented in this blog post.

提交回复
热议问题