Order by enum description

前端 未结 6 1632
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 10:55

I am working on an ASP.NET MVC projet using EF code first, and I am facing a situation where I need to order by an enum description:

public partial class Ite         


        
6条回答
  •  Happy的楠姐
    2021-01-13 11:23

    Change my database column to a string (the enum description) instead of the enum itself (but sounds like a hack to me).

    Opposite, for data-driven application it's better to describe Item property in the database reference table MyItemProperty(MyPropKey,MyPropDescription) and have MyPropKey column in your Items table.

    It has a few benefits, e.g.

    • allow to add new property values without need to change code;
    • allow to write SQL reports having all information in the database without writing c#;
    • performance optimisation can be done on SQL level just by requesting one page;
    • no enum - less code to maintain.

提交回复
热议问题