如何在LINQ查詢中獲取顯示/描述枚舉?獲取顯示在LINQ中的枚舉
例如
var query = dbo.Records.AsQueryable()
.Select(x => new
{
Id = x.Id,
Care = new
{
x.StartDate,
x.ForwardedBy,
},
Prescriptions = x.Prescriptions.Select(p => new
{
p.Medicament,
p.IntervalUse //My Enum, how get Display name?
}),
}).OrderByDescending(x => x.Id);
此查詢是一個exampleand我需要AsQueryable
在我的數據庫
任何原因,你不能只把它作爲'enum'並獲得顯示名稱在視圖或您的形式?這通常是首選的方法。 –
是什麼意思顯示/描述?你在你的枚舉上有[DisplayNameAttribute] s,還是你在談論枚舉的名字 –
@JoshK我回到json – user98498