forked from ddrilling/AsbCloudServer
Add explicitly props conversion to json for other dbProviders.
This commit is contained in:
parent
6d07ca1a3c
commit
d6b5a9507b
@ -11,6 +11,28 @@ namespace AsbCloudDb
|
|||||||
{
|
{
|
||||||
public static class EFExtentions
|
public static class EFExtentions
|
||||||
{
|
{
|
||||||
|
private static System.Text.Json.JsonSerializerOptions jsonSerializerOptions = new()
|
||||||
|
{
|
||||||
|
AllowTrailingCommas = true,
|
||||||
|
WriteIndented = true,
|
||||||
|
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString |
|
||||||
|
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasJsonConversion<TProperty>(
|
||||||
|
this Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> builder)
|
||||||
|
=> HasJsonConversion(builder, jsonSerializerOptions);
|
||||||
|
|
||||||
|
public static Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasJsonConversion<TProperty>(
|
||||||
|
this Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> builder,
|
||||||
|
System.Text.Json.JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
builder.HasConversion(
|
||||||
|
s => System.Text.Json.JsonSerializer.Serialize(s, jsonSerializerOptions),
|
||||||
|
s => System.Text.Json.JsonSerializer.Deserialize<TProperty>(s, jsonSerializerOptions)!);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
static Dictionary<Type, IQueryStringFactory> QueryFactories { get; set; } = new();
|
static Dictionary<Type, IQueryStringFactory> QueryFactories { get; set; } = new();
|
||||||
|
|
||||||
static QueryStringFactory<T> GetQueryStringFactory<T>(DbSet<T> dbSet)
|
static QueryStringFactory<T> GetQueryStringFactory<T>(DbSet<T> dbSet)
|
||||||
|
@ -56,6 +56,14 @@ namespace AsbCloudDb.Model
|
|||||||
public DbSet<WITS.Record60> Record60 => Set<WITS.Record60>();
|
public DbSet<WITS.Record60> Record60 => Set<WITS.Record60>();
|
||||||
public DbSet<WITS.Record61> Record61 => Set<WITS.Record61>();
|
public DbSet<WITS.Record61> Record61 => Set<WITS.Record61>();
|
||||||
|
|
||||||
|
private System.Text.Json.JsonSerializerOptions jsonSerializerOptions = new()
|
||||||
|
{
|
||||||
|
AllowTrailingCommas = true,
|
||||||
|
WriteIndented = true,
|
||||||
|
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString |
|
||||||
|
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||||
|
};
|
||||||
|
|
||||||
public AsbCloudDbContext() : base()
|
public AsbCloudDbContext() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -76,12 +84,47 @@ namespace AsbCloudDb.Model
|
|||||||
modelBuilder.HasPostgresExtension("adminpack")
|
modelBuilder.HasPostgresExtension("adminpack")
|
||||||
.HasAnnotation("Relational:Collation", "Russian_Russia.1251");
|
.HasAnnotation("Relational:Collation", "Russian_Russia.1251");
|
||||||
|
|
||||||
|
modelBuilder.Entity<Deposit>(entity =>
|
||||||
|
{
|
||||||
|
entity.Property(e => e.Timezone)
|
||||||
|
.HasJsonConversion();
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<Cluster>(entity =>
|
modelBuilder.Entity<Cluster>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasOne(d => d.Deposit)
|
entity.HasOne(d => d.Deposit)
|
||||||
.WithMany(p => p.Clusters)
|
.WithMany(p => p.Clusters)
|
||||||
.HasForeignKey(d => d.IdDeposit)
|
.HasForeignKey(d => d.IdDeposit)
|
||||||
.HasConstraintName("t_cluster_t_deposit_id_fk");
|
.HasConstraintName("t_cluster_t_deposit_id_fk");
|
||||||
|
|
||||||
|
entity.Property(e => e.Timezone)
|
||||||
|
.HasJsonConversion();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Well>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasOne(d => d.Cluster)
|
||||||
|
.WithMany(p => p.Wells)
|
||||||
|
.HasForeignKey(d => d.IdCluster)
|
||||||
|
.HasConstraintName("t_well_t_cluster_id_fk");
|
||||||
|
|
||||||
|
entity.HasOne(d => d.Telemetry)
|
||||||
|
.WithOne(p => p.Well)
|
||||||
|
.HasForeignKey<Well>(d => d.IdTelemetry)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull)
|
||||||
|
.HasConstraintName("t_well_t_telemetry_id_fk");
|
||||||
|
|
||||||
|
entity.Property(e => e.Timezone)
|
||||||
|
.HasJsonConversion();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Telemetry>(entity =>
|
||||||
|
{
|
||||||
|
entity.Property(e => e.Info)
|
||||||
|
.HasJsonConversion();
|
||||||
|
|
||||||
|
entity.Property(e => e.TimeZone)
|
||||||
|
.HasJsonConversion();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<WellComposite>(entity =>
|
modelBuilder.Entity<WellComposite>(entity =>
|
||||||
@ -175,20 +218,6 @@ namespace AsbCloudDb.Model
|
|||||||
.IsUnique();
|
.IsUnique();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<Well>(entity =>
|
|
||||||
{
|
|
||||||
entity.HasOne(d => d.Cluster)
|
|
||||||
.WithMany(p => p.Wells)
|
|
||||||
.HasForeignKey(d => d.IdCluster)
|
|
||||||
.HasConstraintName("t_well_t_cluster_id_fk");
|
|
||||||
|
|
||||||
entity.HasOne(d => d.Telemetry)
|
|
||||||
.WithOne(p => p.Well)
|
|
||||||
.HasForeignKey<Well>(d => d.IdTelemetry)
|
|
||||||
.OnDelete(DeleteBehavior.SetNull)
|
|
||||||
.HasConstraintName("t_well_t_telemetry_id_fk");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity<RelationCompanyWell>(entity =>
|
modelBuilder.Entity<RelationCompanyWell>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasKey(nameof(RelationCompanyWell.IdCompany), nameof(RelationCompanyWell.IdWell));
|
entity.HasKey(nameof(RelationCompanyWell.IdCompany), nameof(RelationCompanyWell.IdWell));
|
||||||
@ -241,6 +270,18 @@ namespace AsbCloudDb.Model
|
|||||||
.IsUnique();
|
.IsUnique();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Measure>(entity =>
|
||||||
|
{
|
||||||
|
entity.Property(e => e.Data)
|
||||||
|
.HasJsonConversion();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<FileInfo>(entity =>
|
||||||
|
{
|
||||||
|
entity.Property(e => e.PublishInfo)
|
||||||
|
.HasJsonConversion();
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<FileMark>(entity =>
|
modelBuilder.Entity<FileMark>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasOne(d => d.User)
|
entity.HasOne(d => d.User)
|
||||||
@ -278,6 +319,8 @@ namespace AsbCloudDb.Model
|
|||||||
{
|
{
|
||||||
entity.HasKey(e => new { e.IdWell, e.StartDate })
|
entity.HasKey(e => new { e.IdWell, e.StartDate })
|
||||||
.HasName("t_id_well_date_start_pk");
|
.HasName("t_id_well_date_start_pk");
|
||||||
|
entity.Property(e => e.Info)
|
||||||
|
.HasJsonConversion();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<TelemetryDataSaubStat>(entity =>
|
modelBuilder.Entity<TelemetryDataSaubStat>(entity =>
|
||||||
@ -294,6 +337,11 @@ namespace AsbCloudDb.Model
|
|||||||
.HasConstraintName("t_schedule_t_driller_id_driller");
|
.HasConstraintName("t_schedule_t_driller_id_driller");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<SetpointsRequest>(entity => {
|
||||||
|
entity.Property(e => e.Setpoints)
|
||||||
|
.HasJsonConversion();
|
||||||
|
});
|
||||||
|
|
||||||
FillData(modelBuilder);
|
FillData(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user