0

检查此代码片段。

using (AttendanceDataContext db = new AttendanceDataContext())
{
var attendance = db.attendpunches.Select(at => new RawEmployeeCheckInOutInfo
                    {
                        CheckTime = at.punchtime.Value,
                        Direction = ((AttendanceDirection)at.direction.Value).ToString()
                    });

...

AttendanceDirection 是枚举,它是...

public enum AttendanceDirection : int
{
    CheckIn = 1,
    CheckOut = 2
}

问题是 Direction = ((AttendanceDirection)at.direction.Value).ToString() 总是返回字节值。

4

1 回答 1

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()
                    });
于 2013-02-05T08:54:01.797 回答