2016-11-09 13 views
1

このコードはMVCであり、私はEntity Framework Coreを使用して、このようなもののASP.net Coreで何かをする必要があり、またはDataAnnotationsと(私はModelBuilder(Entity Framework Core)DbModelBuilder(MVC Entity Framework)からすでにパラメータを変更した)OnModelCreating Entity Frameworkのコア

protected override void OnModelCreating(ModelBuilder modelBuilder) 
     { 
      modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>(); //error: Conventions is not recognized 
      base.OnModelCreating(modelBuilder); 
      modelBuilder.Entity<tbl_Line>() 
       .HasMany(d => d.tbl_Policy) 
       .WithRequired(c => c.tbl_Line) //error WithRequired not recognized 
       .HasForeignKey(c => c.int_lineID); 
     } 

私はEntity Framework Coreでそれを使用しようとしている多少の誤差があります。

の1- 'ModelBuilder' does not contain a definition for 'Conventions' and no extension method 'Conventions' accepting a first argument of type 'ModelBuilder' could be found (are you missing a using directive or an assembly reference?)

2 - 'CollectionNavigationBuilder<tbl_Line, tbl_Policy>' does not contain a definition for 'WithRequired' and no extension method 'WithRequired' accepting a first argument of type 'CollectionNavigationBuilder<tbl_Line, tbl_Policy>' could be found (are you missing a using directive or an assembly reference?)

+1

良い出発点 - [EF Core vs. EF6.x](https://docs.efproject.net/en/latest/efcore-vs-ef6/index.html#) –

+0

@IvanStoevページが見つかりません。私は、設定を使って自分のefコアコンテキストファイルにマップを追加したいと思っています。同じファイルにマッピングを書くのは面倒です。方法がありますか、またはAlexGhがそれを行ったのと同じ方法で追加する必要があります。 – nakulchawla09

+0

@ nakulchawla09最近のドキュメントは[こちら](https://docs.microsoft.com/en-us/ef/efcore-and-ef6/)です。まもなく、EF6のようなEFコアの規約や設定はまだサポートされていません(AFAIKには追加予定がありますが、私はいつか分かりません)ので、今は 'modelBuilder'で悩んでいます。 –

答えて

0

ModelBuilder.Configurationsのためのサポートがあるまで私は、拡張メソッドを持つ古いEntity Frameworkの建設エミュレート:その後、

public static EntityTypeBuilder<Project> Map(this EntityTypeBuilder<Project> cfg) 
{ 
    cfg.ToTable("sql_Projects"); 

    // Primary Key 
    cfg.HasKey(p => p.Id); 

    cfg.Property(p => p.Id) 
     .IsRequired() 
     .HasColumnName("ProjectId"); 

    return cfg; 
} 

と、このようなをOnModelCreating から呼び出しを...

protected override void OnModelCreating(ModelBuilder modelBuilder) 
{ 
    modelBuilder.Entity<Project>().Map(); 
    base.OnModelCreating(modelBuilder); 
} 

これはちょっと面倒ですが、私は、数十メインDbContext内のエンティティ

+0

この方法は存在しないようです。 –

+0

どの方法を参考にしていますか? – Neilski

関連する問題