Ich entwickle eine C# -Bibliothek mit .NET Framework 4.6.2 und Entity Framework 6.1.3 Code zuerst, um es in einer SQL Server 2012-Datenbank zu verwenden.Multiplizität der Principal Role muss 0..1
Ich habe diese zwei Klassen:
public class Product
{
public int ProductId { get; set; }
// Omitted for brevity
public virtual ICollection<ProductionOrder> ProductionOrders { get; set; }
}
public class ProductionOrder
{
public int ProductionOrderId { get; set; }
public int? ProductId { get; set; }
// Omitted for brevety
public virtual Product Product { get; set; }
// Omitted for brevity
}
Mit diesen beiden Konfigurationsklassen:
class ProductionOrderConfiguration : EntityTypeConfiguration<ProductionOrder>
{
public ProductionOrderConfiguration()
{
HasKey(po => po.ProductionOrderId);
Property(c => c.ProductionOrderId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(po => po.ProductionOrderId)
.IsRequired();
Property(po => po.ProductId)
.IsOptional();
// Omitted for brevity
}
}
class ProductConfiguration : EntityTypeConfiguration<Product>
{
public ProductConfiguration()
{
HasKey(p => p.ProductId);
Property(p => p.ProductId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
// Omitted for brevity
HasMany(p => p.ProductionOrders)
.WithRequired(po => po.Product)
.HasForeignKey(p => p.ProductId);
}
}
Aber, wenn ich versuche, es zu laufen, ich die folgende Meldung erhalten, dass ich nicht verstehe, :
Product_ProductionOrders: Multiplicity ist ‚in Rollen nicht gültig Product_ProductionOrders_Sour ce 'in Beziehung ' Product_ProductionOrders '. Da alle Eigenschaften in der abhängigen Rolle nullfähig sind, muss die Multiplizität der Hauptrolle '0..1' lauten.
Das Modell Ich versuche darzustellen ist:
Ein Fertigungsauftrag Null oder ein Produkt haben. Und ein Produkt könnte in einer oder n Produktionsaufträge sein.
Ich weiß nicht, wie man die Multiplizität der Principal Role auf '0..1' setzt.