using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace ProductCatalog.Models { [Table("Product")] public class Product { public int ProductId { get; set; } public string Name { get; set; } public string Color { get; set; } public string Size { get; set; } public decimal Price { get; set; } public int Quantity { get; set; } public int CompanyID { get; set; } [NotMapped] public string[] Tags { get { return _Tags == null ? null : JsonConvert.DeserializeObject(_Tags); } set { _Tags = JsonConvert.SerializeObject(value); } } internal string _Tags { get; set; } [NotMapped] public Properties Data { get { return (this._Data == null) ? null : JsonConvert.DeserializeObject(this._Data); } set { _Data = JsonConvert.SerializeObject(value); } } internal string _Data { get; set; } } public class Properties { public string Type { get; set; } public string MadeIn { get; set; } } public class ProductCatalogContext : DbContext { public ProductCatalogContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .Property(x => x.ProductId) .HasDefaultValueSql("NEXT VALUE FOR ProductId"); modelBuilder.Entity() .Property(b => b._Tags).HasColumnName("Tags"); modelBuilder.Entity() .Property(b => b._Data).HasColumnName("Data"); } public DbSet Products { get; set; } } }