此刻我的课程看起来像这样
public class PriceHistory
{
public Guid ID { get; set; }
public double Price { get; set; }
public DateTime DateTime { get; set; }
//public Guid ProductID { get; set; }
//public Product Product { get; set; }
public string StoreIdentifier { get; set; }
public string ProductID { get; set; }
public Product Product { get; set; }
}
public class Product
{
public Guid ID { get; set; }
public string Name { get; set; }
public string Link { get; set; }
public string StoreIdentifier { get; set; }
public Guid DetailID { get; set; }
public Detail Detail { get; set; }
public Guid SnapshotID { get; set; }
public Snapshot Snapshot { get; set; }
public string ImageID { get; set; }
public Image Image { get; set; }
public double Price { get; set; }
public List<PriceHistory> PriceHistories { get; set; }
}
我想配置EF Core,以在Product和PriceHistory之间建立一对多关系。无论我做什么,我都会对PriceHistory引入唯一的约束,这不是我要尝试做的。我正在尝试使它具有多个PriceHistories的产品,并且其导航属性位于StoreIdentifier字符串上。我现有的设置(引入了唯一约束)是
modelBuilder.Entity<Product>().HasMany(x => x.PriceHistories).WithOne(x => x.Product)
.HasForeignKey(x => x.StoreIdentifier).HasPrincipalKey(x => x.StoreIdentifier);
我该如何设置?