检查此代码小部件。
using (AttendanceDataContext db = new AttendanceDataContext())
{
var attendance = db.attendpunches.Select(at => new RawEmployeeCheckInOutInfo
{
CheckTime = at.punchtime.Value,
Direction = ((AttendanceDirection)at.direction.Value).ToString()
});
...
AttendanceDirection是enum,这是......
public enum AttendanceDirection : int
{
CheckIn = 1,
CheckOut = 2
}
问题是Direction =((AttendanceDirection)at.direction.Value).ToString()总是返回字节值。
答案 0 :(得分:4)
我怀疑问题是ToString
在数据库端有效执行,而不知道枚举名称。试试这个:
var attendance = db.attendpunches
.Select(at => new { CheckTime = at.punchtime.Value,
Direction = at.direction.Value })
.AsEnumerable() // Do the rest of the query in-process...
.Select(at => new RawEmployeeCheckInOutInfo {
CheckTime = at.CheckTime,
Direction = ((AttendanceDirection) at.Direction).ToString()
});