2

ここからのアドバイスに従っています:

値が 24:00:00 を超える .Net Timespan を格納するための正しい SQL タイプは何ですか?

TimesheetEntry という名前のモデル内には、次のものがあります。

public Int64 NetLengthTicks { get; set; }

[NotMapped]
public TimeSpan NetLength
{
    get { return TimeSpan.FromTicks(NetLengthTicks); }
    set { NetLengthTicks = value.Ticks; }
}

私はこれを試みています:

var shiftsData = from shift in filteredShifts
                where shift.IsDeleted == false
                select new
                {
                    shift.TimesheetShiftId,
                    shift.UserId,
                    shift.HasShiftEnded,
                    shift.StartTime,
                    shift.EndTime,
                    Entries = from entry in shift.Entries
                            where entry.IsDeleted == false
                            select new
                            {
                                entry.TimesheetEntryId,
                                entry.TimesheetShiftId,
                                entry.EntryType,
                                entry.StartTimeSpan,
                                entry.NetLength,
                            }
                };

私は例外を受け取ります:

The specified type member 'NetLength' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

投影を次のように変更しようとしました。

NetLength = TimeSpan.FromTicks(entry.NetLengthTicks)

しかし、それは例外を与えました:

LINQ to Entities does not recognize the method 'System.TimeSpan FromTicks(Int64)' method, and this method cannot be translated into a store expression.

次に、変換を行う式を作成してみました。

public static Expression<Func<DAL.Models.TimesheetEntry, TimeSpan>> NetLengthExpression
{
    get
    {
        return e => TimeSpan.FromTicks(e.NetLengthTicks);
    }
}

// in the projection
NetLength = NetLengthExpression

しかし、それは投げました:

The LINQ expression node type 'Lambda' is not supported in LINQ to Entities.

クエリで返される TimeSpan として NetLength を公開する方法はありますか?

4

1 に答える 1