DateTime
とTimeZoneInfo
を表す独自の構造体を定義しましたので、タイムゾーンに関する情報を保持しながらUTC時間で作業できます。Web Api ODataカスタムタイプのクエリ
これらのオブジェクトをODataクエリで取得したいのですが、このタイプのプロパティで$orderby
を使用しようとすると失敗します。 $orderBy=Timestamp/Value/UniversalTime
を質問したところ結果が得られましたが、私はちょうど$orderBy=Timestamp
このタイプのコレクションを注文する可能性はありますか?
public struct DateTimeWithZone : IComparable<DateTime>, IComparable<DateTimeWithZone>, IFormattable
{
private readonly DateTime _utcDateTime;
private readonly TimeZoneInfo _timeZone;
public DateTimeWithZone(DateTime dateTime, TimeZoneInfo timeZone)
{
if (timeZone == null)
{
throw new NoNullAllowedException(nameof(timeZone));
}
_utcDateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
_timeZone = timeZone;
}
...
}
次のように定義されたモデルで
:
public class ClientViewModel
{
public string Name { get; set; }
public DateTimeWithZone? Timestamp { get; set; }
}
をそして、これは、使用されている方法です:私たちは、複雑な型を持ついくつかの同様の問題があった
public IHttpActionResult GetAll(ODataQueryOptions<ClientViewModel> options)
{
var fromService = _clientsClient.GetAllClients().MapTo<ClientViewModel>(MappingStrategy).AsQueryable();
var totalCount = fromService.Count();
var results = options.ApplyTo(fromService); // <-- Fails here
return Ok(new PageResult<ClientViewModel>(
results as IEnumerable<ClientViewModel>,
Request.ODataProperties().NextLink,
totalCount));
}
がThe $orderby expression must evaluate to a single value of primitive type.