summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2024-01-12 15:22:43 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2024-01-12 15:22:43 +0300
commitc8bf31ab502c3b8a585c73a87df77e4f4e09a6ca (patch)
tree16e24226edb4cfd803b92e5df6925fa73c4749f7
parent2d188d76577f7ae5f9ecf4d876e10760bd3d89ba (diff)
Add actual postgresql type conversions
-rw-r--r--RhSolutions.Api/Models/RhsolutionsContext.cs7
-rw-r--r--RhSolutions.Api/Models/SkuConverter.cs11
2 files changed, 15 insertions, 3 deletions
diff --git a/RhSolutions.Api/Models/RhsolutionsContext.cs b/RhSolutions.Api/Models/RhsolutionsContext.cs
index e9df2eb..be0fcb5 100644
--- a/RhSolutions.Api/Models/RhsolutionsContext.cs
+++ b/RhSolutions.Api/Models/RhsolutionsContext.cs
@@ -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));
}
}
diff --git a/RhSolutions.Api/Models/SkuConverter.cs b/RhSolutions.Api/Models/SkuConverter.cs
new file mode 100644
index 0000000..c66d851
--- /dev/null
+++ b/RhSolutions.Api/Models/SkuConverter.cs
@@ -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))
+ {
+ }
+}