简体   繁体   English

如何从一个数据库(ASP.NET MVC)创建多个表?

[英]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.

相关问题 如何在asp.net mvc中使用Linq从数据库中删除多条记录 - how delete more than one record from database using Linq in asp.net mvc 从 ASP .NET MVC 3 中的数据库中获取多个项目 - Getting more than one item from a database in ASP .NET MVC 3 从多个表中删除用户记录ASP.Net MVC - Delete user records from more than one table ASP.Net mvc 如何使用ASP.NET MVC将数据从一个数据库表移动到同一数据库的另一表? - How to move data from one database table to another table of same database using ASP.NET MVC? 如何从SqlDataSource asp.net中的多个表中进行选择 - How can i select from more than one table in a SqlDataSource asp.net ASP.Net MVC 4-一个以上的线程 - ASP.Net MVC 4 - more than one thread 在 ASP.NET MVC 中是否可以有多个路由? - Is it possible to have more than one routing in ASP.NET MVC? Ajax.beginform 提交时会在 asp.net mvc 的数据库中创建多个条目 - Ajax.beginform when submitting it creates more than one entry in database in asp.net mvc Asp.net MVC Nhibernate:不能通过联接视图修改多个基本表 - Asp.net MVC Nhibernate : Can not modify more than one base table through a join view 与Entity Framework ASP.net MVC中的多个表的可选关系 - Optional relationship to more than one table in Entity Framework ASP.net MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM