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 に答える