Die Saatgutentität für Entitätstyp 'x' kann nicht hinzugefügt werden, da der Wert für die erforderliche Eigenschaft "..IC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Die Saatgutentität für Entitätstyp 'x' kann nicht hinzugefügt werden, da der Wert für die erforderliche Eigenschaft "..I

Post by Anonymous »

Ich spiele mit EF Core 2.1 Preview 2 . />
Mein Modell ist eine einfache PoCO -Klasse, die keine Annotation hat. < /p>

public class Tenant {
public int TenantID {get; set;}
public string Name {get; set;}
}
< /code>

In meiner DBContext < /code> Inneren OnModelCreating < /code> ist das DB -Modell, das als < /p>

definiert istmodelBuilder.Entity(e => {
e.HasKey(m => m.TenantID)
.HasName("PK_Tenants");

e.Property(m => m.TenantID)
.UseSqlServerIdentityColumn();

e.Property(m => m.Name)
.IsRequired()
.HasMaxLength(256);
}
< /code>

und die Saatgutmethode ist definiert als: < /p>

modelBuilder.Entity().HasData(new []{
new Tenant {
TenantID = 0,
Name = "SystemTenant",
}
});
< /code>



Während des StartAP, wenn ctx.database.migratate () ausgeführt wird, habe ich Ausnahme:
die Saatgut -Entität für Entitätstyp 'Mieter kann nicht hinzugefügt werden>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post