这个代码在MVC
,我需要做这样的事情,但在ASP.net Core
,使用Entity Framework Core
,或DataAnnotations
(我已经从DbModelBuilder(MVC Entity Framework)
改变参数ModelBuilder(Entity Framework Core)
)OnModelCreating实体框架的核心
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?)
一个好的起点 - [EF核心与EF6.x](https://docs.efproject.net/en/latest/efcore-vs-ef6/index.html#) –
@IvanStoev找不到页面。即使我想使用配置在我的核心上下文文件中添加地图。将映射写入同一个文件看起来很乱。有没有办法,或者需要像AlexGh所做的那样添加它。 – nakulchawla09
@ nakulchawla09最近的文档是[here](https://docs.microsoft.com/en-us/ef/efcore-and-ef6/)。简而言之,EF6中仍然不支持惯例和/或EF内核的配置(AFAIK有计划添加,但我不知道何时),所以现在你只能使用'modelBuilder'。 –