繁体   English   中英

无法使用.net在给定的数据库连接中连接到表Azure SQL

[英]Can't Connect to the table azure SQL in given DB connection using .net

我的问题是Azure DB连接工作正常,但是当我使用链接 https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-中给出的示例Todo时dotnet-sql数据库

因此我已经在数据库中创建了名为“ PhotoTable”的表,但是每次我运行示例(asp.net)时,它都会在我的数据库中创建它自己的表(Todoes表)(已经创建了数据库,并且它与现有数据库的连接良好)所以问题是它没有与mt table连接,我已经完成了控制器和所有其他东西的更改,但是它没有用,如果有人知道如何与现有表连接,请告诉我,谢谢(如果有更多信息,需要,请让我知道,我已经添加了我的表列表和需要连接的表的屏幕截图,并用红色突出显示了) 在此处输入图片说明

这是有关如何与数据库中现有表连接的教程

下面是具有与表相同的属性的Student类。

public class Student
    {
        public int ID { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }
        public string Address { get; set; }
    }

StudentMap类用于映射数据库中的现有表。

public class StudentMap : EntityTypeConfiguration<Student>
    {
        public int MapID { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }
        public string Address { get; set; }
        public StudentMap()
        {
            // Table & parimary key Mappings
            this.ToTable("StudentMap");
            this.HasKey(t => t.ID);
        }

    }

SchoolContext是对数据库的引用。 在此代码中,我们使用上面声明的StudentMap进行配置。

public class SchoolContext : DbContext
    {
        public SchoolContext() : base("SchoolContext")
        {
        }
        public DbSet<Student> Students { get; set; }
        public DbSet<StudentMap> StudentMaps { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Entity<StudentMap>().HasKey(x => new { x.MapID });
        }
    }

注意 :设置在不同的密钥StudentStudentMap类以便schoolcontext能够正确区分它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM