Hello,
I am using EF Core 6 and SQL server express and trying to migrate my entities. I am getting this error.
Here are my entities
And Dbcontext
I am using EF Core 6 and SQL server express and trying to migrate my entities. I am getting this error.
The properties 'Order.Id', 'Order.OrderNumber' are configured to use 'Identity' value generation and are mapped to the same table 'Orders', but only one column per table can be configured as 'Identity'. Call 'ValueGeneratedNever' in 'OnModelCreating' for properties that should not use 'Identity'
Here are my entities
Entities:
public class Order
{
public int Id { get; set; }
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int OrderNumber { get; set; }
[Required]
public DateTime OrderDateTime { get; set; }
[Required]
[MaxLength(250)]
public string CustomerName { get; set; }
[Required]
[MaxLength(250)]
public string VendorName { get; set; }
public string Status { get; set; }
[MaxLength(50)]
public string DoneBy { get; set; }
public List<OrderDetail> OrderDetails { get; set; }
}
public class OrderDetail
{
public int Id { get; set; }
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductNumber { get; set; }
[Required]
[MaxLength(100)]
public string ProductCode { get; set; }
[Required]
[MaxLength(250)]
public string ProductName { get; set; }
[Required]
public int BuyQuantity { get; set; }
[Required]
public int SellQuantity { get; set; }
public double CostRatio { get; set; }
public double UnitCost { get; set; }
public double TotalBuyPrice { get; set; }
public double TotalSellPrice { get; set; }
[MaxLength(150)]
public string ShippingNumber { get; set; }
public string Status { get; set; }
[MaxLength(150)]
public string TrackingNumber { get; set; }
[MaxLength(400)]
public string Description { get; set; }
public int OrderId { get; set; }
public Order Order { get; set; }
}
And Dbcontext
DbContext:
...
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrdersDetail { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//relations
modelBuilder.Entity<Order>()
.Property(p => p.OrderNumber)
.ValueGeneratedOnAdd();
modelBuilder.Entity<OrderDetail>()
.Property(p => p.ProductNumber)
.ValueGeneratedOnAdd();