Activity: Adding a Supplier Entity that Denotes the Supplier of a Product

Scenario

You want to add a supplier entity that denotes the supplier of a product.

Aim

Add a supplier entity for a product.

Steps for completion

  1. We can add Supplier class as follows:
namespace RestBuy.Entities
{
class Supplier : BaseEntity
{
public string Name { get; set; }
}
}

Optionally we can add a Supplier property to Product or a SupplierId depending on if we want them to be in the same aggregate or not. This is a design choice.

  1. And for the migrations we use the following code:
void ConfigureSupplier(EntityTypeBuilder<Supplier>builder)
{
builder.ToTable("Suppliers");
builder.HasKey(ci => ci.Id);
builder.Property(ci => ci.Name)
.IsRequired()
.HasMaxLength(50);
builder.HasIndex(c => c.Name).IsUnique();
}