using Props.Models; using IdentityServer4.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Text.Json; using Microsoft.EntityFrameworkCore.ChangeTracking; namespace Props.Data { public class ApplicationDbContext : ApiAuthorizationDbContext { public ApplicationDbContext( DbContextOptions options, IOptions operationalStoreOptions) : base(options, operationalStoreOptions) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity() .Property(e => e.Order) .HasConversion( v => JsonSerializer.Serialize(v, null), v => JsonSerializer.Deserialize>(v, null), new ValueComparer>( (a, b) => a.SequenceEqual(b), c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), c => (IList) c.ToList() ) ); modelBuilder.Entity() .Property(e => e.ShopStates) .HasConversion( v => JsonSerializer.Serialize(v, null), v => JsonSerializer.Deserialize(v, null), new ValueComparer( (a, b) => a.Equals(b), c => c.GetHashCode(), c => c.Clone() ) ); } } }