Я попробовал приведенный ниже код, но он создает уникальное ограничение.
Код: Выделить всё
[Table("VendorBrandsPromotion")]
public class VendorBrandPromoTable
{
public Guid Id { get; set; }
public Guid VendorId { get; set; }
public string Brand { get; set; }
public string Location { get; set; }
public string CustomerGroup { get; set; }
public bool IsEnableDateValidation { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string HeaderText { get; set; }
public string BodyText { get; set; }
public string PromotionText { get; set; }
public bool IsActive { get; set; }
public int CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
public int? UpdatedBy { get; set; }
public DateTime? UpdatedDate { get; set; }
public virtual ICollection
BrandsPromotionProducts { get; set; }
public virtual ICollection
BrandsPromotionImages { get; set; }
//Config
public class DbConfiguration : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(v => new { v.Id, v.VendorId });
builder.Property(v => v.Brand).HasMaxLength(500).IsRequired();
builder.Property(v => v.Location).HasMaxLength(500);
builder.Property(v => v.CustomerGroup).HasMaxLength(500);
builder.Property(v => v.HeaderText).HasMaxLength(500);
builder.Property(v => v.BodyText).HasMaxLength(1000);
builder.Property(v => v.PromotionText).HasMaxLength(80);
builder.HasMany(v => v.BrandsPromotionProducts).WithOne(v => v.VendorBrandPromo).HasForeignKey(v => new { v.VendorPromotionId }).HasPrincipalKey(v => new { v.Id });
builder.HasMany(v => v.BrandsPromotionImages).WithOne(v => v.VendorBrandPromo).HasForeignKey(v => new { v.VendorPromotionId }).HasPrincipalKey(v => new { v.Id });
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... -as-unique