CosmosDB コンテナーのデータを使用して API エンドポイントを作成したいと考えています。データ構造は次のとおりです。
{
"id": "28.02.2022 09:31:42",
"time": 1646037099,
"states": [
[
"aa56db",
"UAL339 ",
"United States",
1646037098,
1646037099,
-84.9531,
25.9777,
11277.6,
false,
239.52,
25.85,
0,
null,
11811,
null,
false,
0,
4
],
[
"3c403f",
"FME ",
"Germany",
1646037012,
1646037012,
13.5172,
52.3712,
null,
true,
5.14,
247.5,
null,
null,
null,
null,
false,
0,
17
],
まず、次のようなモデル「OpenSky」を作成しました。
public class OpenSky
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("time")]
public decimal? Time { get; set; }
[JsonProperty("states")]
public List<List<**OpenSkyFlight**>> States { get; set; }
}
プロパティの状態は、オブジェクト タイプOpenSkyFlightのリストのリストです。OpenSkyFlight モデルは次のようになります。
public class OpenSkyFlight
{
public string Icao24 { get; set; }
public string Callsign { get; set; }
public string OriginCountry { get; set; }
public int? TimePosition { get; set; }
public int? LastContact { get; set; }
public float? Longitude { get; set; }
public float? Latitude { get; set; }
public float? BaroAltitude { get; set; }
public bool? OnGround { get; set; }
public float? Velocity { get; set; }
public float? TrueTrack { get; set; }
public float? VerticalRate { get; set; }
public string Sensors { get; set; }
public float? GeoAltitude { get; set; }
public string Squawk { get; set; }
public bool? Spi { get; set; }
public int? PositionSource { get; set; }
}
問題は、これらのjsonプロパティの「状態」をOpenSkyFlightのようなオブジェクトタイプにフラット化する方法がわかりません。Context.cs で次のことを試しました。
// OpenSky
modelBuilder.Entity<OpenSky>()
.Property(p => p.Id)
.ToJsonProperty("id");
modelBuilder.Entity<OpenSky>()
.Property(p => p.Time)
.ToJsonProperty("time");
modelBuilder.Entity<OpenSky>()
.Property(p => p.States)
.HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<List<List<object>>>(v => new Icao24 = JsonConvert.ToString(v[0]))
)
.ToJsonProperty("states");
前もって感謝します!