[英]How to create more than one table from one database (ASP.NET MVC)?
I am working with ASP.NET MVC.我正在使用 ASP.NET MVC。 The plan is to create a Website where you can switch between to tables.计划是创建一个网站,您可以在其中切换表格。
The website works with one table but the problem is that when I switch to the other table I can not see the table.该网站使用一张桌子,但问题是当我切换到另一张桌子时,我看不到这张桌子。
I use one database for the program and created a second public class for the second table in my Context.cs.我为程序使用了一个数据库,并为我的 Context.cs 中的第二个表创建了第二个公共类。
For the first table I used:对于我使用的第一个表:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ImpEx>()
.HasIndex(b => b.Ex_Nr)
.IsUnique();
}
But for the second I am not allowed to use a second method of it.但是对于第二个我不允许使用它的第二种方法。
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ImpExQ30>()
.HasIndex(d => d.Ex_Nr)
.IsUnique();
}
The error is that I am not allowed to use a second method because I have one in my DB already错误是我不允许使用第二种方法,因为我的数据库中已经有一个
You cannot have two OnModelCreating methods in one context.在一个上下文中不能有两个 OnModelCreating 方法。
But you can have two or many more builder statements:但是你可以有两个或更多的构建器语句:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ImpEx>()
.HasIndex(b => b.Ex_Nr)
.IsUnique();
modelBuilder.Entity<ImpExQ30>()
.HasIndex(d => d.Ex_Nr)
.IsUnique();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.