I've been searching about how to convert enums to predicate in lambda expression/LINQ query to EF. For example, I have below enums:
public enum MyEnum
{
[Display(DisplayName="FirstDesc")
First = 0,
[Display(DisplayName="SecondDesc")]
Second = 1,
[Display(DisplayName="ThirdDesc")]
Third = 2
}
And my LINQ query is
var query = (from a in context.users
select new { Desc =
case when Status==(int)MyEnum.First ? "FirstDesc" :
case when Status==(int)MyEnum.Second ? "SecondDesc":
case when Status==(int)MyEnum.Third ? "ThirdDesc" : "Unknown" });
I want to achieve that once I add a new item to enum, the linq query automatically adjust the condition to all the items in the Enum.
Any help would be appreciated.