我有枚举:
public enum CmdType {
[Display(Name = "abc")]
AbcEnumIdentifier = 0,
[Display(Name = "xyz")]
XyzEnumIdentifier = 1,
...
}
Run Code Online (Sandbox Code Playgroud)
我想将每个枚举的名称放入我的查询中,但即使使用.WithTranslations()
我也会收到此错误:
LINQ to Entities无法识别方法'System.String GetName(System.Type,System.Object)'方法,并且此方法无法转换为商店表达式.
查询:
var joinedRecord =
(
from m in mTable
join b in bTable on m.Id equals b.aRefId
select new {
aId = a.Id,
aAttrib1 = a.Attrib1
...
bCmdType = Enum.GetName(typeof(CmdType), b.CmdType)
}
).WithTranslations();
Run Code Online (Sandbox Code Playgroud)
如何Enum.GetName(...)
在查询中返回生成的值?