0
0

Add actual postgresql type conversions

This commit is contained in:
Serghei Cebotari 2024-01-12 15:22:43 +03:00
parent 2d188d7657
commit c8bf31ab50
2 changed files with 15 additions and 3 deletions

View File

@ -14,8 +14,9 @@ public class RhSolutionsContext : DbContext
builder.Entity<Product>()
.Property(e => e.ProductSku)
.HasConversion(v => v.ToString(), v => new ProductSku(v));
// builder.Entity<Product>()
// .Property(e => e.DeprecatedSkus)
// .HasPostgresArrayConversion<ProductSku, string>(v => v.ToString(), v => new ProductSku(v));
builder.Entity<Product>()
.PrimitiveCollection(e => e.DeprecatedSkus)
.ElementType()
.HasConversion(typeof(SkuConverter));
}
}

View File

@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace RhSolutions.Models;
internal class SkuConverter : ValueConverter<ProductSku, string>
{
public SkuConverter()
: base(x => x.ToString(), x => new ProductSku(x))
{
}
}