Core Properties and Properties of a Core EntityFramework Core Fluent Model Builder Object

Ok, so in the essence of framework 6, I would have generated a database of keys and properties in one expression:

modelBuilder.Entity<Function>()
                .HasKey(x => x.Id)
                .Property(x => x.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

In the core of entity (7), this does not work:

modelBuilder.Entity<Function>()
                .HasKey(x => x.Id)
                .Property(x => x.Id)
                .ValueGeneratedNever();

Error: "KeyBuilder" does not contain a definition for "Property" and no extension method "Property" that takes the first argument of type "KeyBuilder":

Should it be two separate operators, as shown below, or is there a way to have it in one, as you could in EF6?

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Function>()
                    .HasKey(x => x.Id);

    modelBuilder.Entity<Function>()
                    .Property(x => x.Id)
                    .ValueGeneratedNever();
}
+4
source share
1 answer

Yes, they are shared in the EF Core.

, EF6 PK , EntityTypeConfiguration<TEntityType> ( , , Entity<...>), .

EF Core , KeyBuilder, PK, HasName , , ForSqlServerHasName ForSqlServerIsClustered ..

+4

Source: https://habr.com/ru/post/1668020/


All Articles