Asp.net OnModelCreating在实体框架7中未定义
我试图在EF7中设置模型的关系,但我遇到了问题:Asp.net OnModelCreating在实体框架7中未定义,asp.net,entity-framework,asp.net-core,entity-framework-core,Asp.net,Entity Framework,Asp.net Core,Entity Framework Core,我试图在EF7中设置模型的关系,但我遇到了问题:OnModelCreating方法和DbModelBuilder未定义 过去,我使用EF6,但现在我尝试迁移到EF7 这是我的密码 protected override void OnModelCreating(DbModelBuilder modelBuilder) { //Section -> many Category modelBuilder.Entity<Section>()
OnModelCreating
方法和DbModelBuilder
未定义
过去,我使用EF6,但现在我尝试迁移到EF7
这是我的密码
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Section -> many Category
modelBuilder.Entity<Section>()
.HasMany<Category>(p => p.Categories)
.WithRequired(p => p.Section);
//Section -> many PriceCategory
modelBuilder.Entity<Section>()
.HasMany<PriceCategory>(p => p.PriceCategories)
.WithRequired(p => p.Section);
//Category - many Procedures
modelBuilder.Entity<Category>()
.HasMany<Procedure>(p => p.Procedures)
.WithRequired(p => p.Category);
//PriceCategory - many PriceProcedures
modelBuilder.Entity<PriceCategory>()
.HasMany<PriceProcedure>(p => p.PriceProcedures)
.WithRequired(p => p.PriceCategory);
}
My project.json:
{
"version": "1.0.0-*",
"description": "Domain Class Library",
"authors": [ "Garrus" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
},
"frameworks": {
"net451": { },
"dnxcore50": {}
}
}
你能帮我吗?也许我忘记了一些NuGet包,或者有另一种方法可以在EF7中设置模型关系?应该是这样的:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
....
}
我猜DbModelBuilder被重命名为ModelBuilder了。。。我有很多问题,所以我创建了一个新的ASP.NET 5 MVC项目,在那里复制我的旧模型、控制器、viewa等,一切都很好。(我认为,这是一种奇怪的魔法) 在这里,重写的方法,一切正常
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
我的用法和问题中的一样。
和域的project.json,也许它对面临相同错误的人有用
{
"version": "1.0.0-*",
"description": "Domain Class Library",
"authors": [ "Garrus" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
},
"frameworks": {
"net451": { },
"dnxcore50": { }
}
}
我刚刚知道,onconfigurang方法也是未定义的。保存了我的培根。
{
"version": "1.0.0-*",
"description": "Domain Class Library",
"authors": [ "Garrus" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
},
"frameworks": {
"net451": { },
"dnxcore50": { }
}
}