I am building an API in .Net core using EF core 6.0 as ORM. I have class structure as given below. Can you please guide me on how can I map fields of all 3 classes to one sql table. With the code given, I was not able to map beyond the fields of first class.
B2BOrder.cs
public string CustomerCode { get; set; }
public string DocumentIdentifier{ get; set; }
public OrderHeader OrderHeader { get; set; }
OrderHeader.cs
public string OrderType { get; set; }
public string ContractNumber { get; set; }
public string Activity { get; set; }
public OrderDetails OrderDetails { get; set; }
OrderDetails.cs
public string OrderStatusCode { get; set; }
public string CustomerOrderReference { get; set; }
public string PurchaseOrderNumber { get; set; }
DB Context Class
public class LucRepository : DbContext
{
public virtual DbSet<B2BOrder> B2BOrders { get; protected set; }
public LucRepository(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("Luc");
modelBuilder.ApplyConfiguration(new B2BOrderMapping());
}
}
B2BOrderMapping.cs
public class B2BOrderMapping : IEntityTypeConfiguration<B2BOrder>
{
public void Configure(EntityTypeBuilder<B2BOrder> builder)
{
builder.ToTable("B2BOrders");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id).HasColumnName("Id").ValueGeneratedOnAdd();
builder.Property(x => x.DocumentIdentifier).HasColumnName("DocumentIdentifier");
builder.Property(x => x.CustomerCode).HasColumnName("CustomerCode");
}
}
Thanks in advance !