1
我有一個類「BudgetDetail」是這樣的:標識列不應用於數據庫
public class BudgetDetail
{
public int Id { get; set; }
public Budget Budget{ get; set; }
public int BudgetId { get; set; }
public Product Product { get; set; }
public int ProductId { get; set; }
public byte Quantity { get; set; }
public int Price { get; set; }
public int Iva { get; set; }
public int Total { get; set; }
}
這是此模型的流暢API配置:
public class BudgetDetailConfiguration: EntityTypeConfiguration<BudgetDetail>
{
public BudgetDetailConfiguration()
{
ToTable("BudgetDetails");
HasKey(pd => new { pd.Id, pd.BudgetId, pd.ProductId });
Property(pd => pd.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
}
}
當我做遷移,Id屬性的身份設置爲true,但如果我在數據庫中查看它的身份設置爲false,並且我不知道爲什麼,我猜這是因爲我對此表有複合鍵。
如果您有組合鍵,標識列不起作用?
我不知道你的問題的答案,但包括身份的複合密鑰沒有意義。你只需要標識列就可以是唯一的。添加其他列是多餘的。 –