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

Multi tool use
Multi tool use


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



My question is the Azure DB connection is working perfectly but when i use the sample Todo by given in the link https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-dotnet-sqldatabase



so i have already table in the database called "PhotoTable" but every time i run the sample (asp.net)it creates it own table ( Todoes table)in my DB ( DB is already i created and its connect fine with my existing DB) so the issue is its not connecting with mt table , i have done changing the controller and all other stuff , but it dosen't work, if anyone knows how to connect with existing table please kindly let me know , thanks ( if more information needed please let me know, i have added the screenshot of my table list and the table i need to connect i have highlighted with red)
enter image description here





Did you give the right link? That link is about Azure Storage , but your question is about Azure SQL DB.
– Lee Liu
Jul 2 at 9:55





The sample you provided do not need to use azure sql db and if you have existing tables , then you can just write an ADO.NET repository layer on top of it. Your controller can call these repository layers for DB operation.
– Joey Cai
Jul 2 at 10:11





@Lee Liu I am so sorry for submitting the incorrect link the correct link suppose to be docs.microsoft.com/en-us/azure/app-service/… ( i have updated my question with the correct link now, thank you for trying to help me, hope above details will support to answer the question i have, please let me know your answers , thank you
– Pan Weerasekara
Jul 2 at 14:57





@Joey Cai, I am so sorry for submitting the incorrect link the correct link suppose to be docs.microsoft.com/en-us/azure/app-service/… ( i have updated my question with the correct link now, thank you for trying to help me, hope above details will support to answer the question i have, please let me know your answers , thank you
– Pan Weerasekara
Jul 2 at 14:57




1 Answer
1



Here is the tutorial about how to connect with an existing table in the database.



Below is Student class with the same attributes and properties as of the 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; }
}



The class StudentMap is used to map with the existing table in the database.


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);
}

}



The SchoolContext is the reference to the database. In this code, we are using the StudentMap declared above for configuration.


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 });
}
}



Note: Set the different key in Student and StudentMap class so that the schoolcontext could distinguish them correctly.


Student


StudentMap


schoolcontext





@Weerasekara Any process you get? I test in my site and work fine. If you have any problem, please feel free to let me know.
– Joey Cai
Jul 5 at 1:22






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

MDRuuWbay lEHxXXU,PVGDcN
6iDg,gnLdlCvzAo1HvIMyyXiF5qJoYtP0wxRy7,Y uEfmofQWKC0P

Popular posts from this blog

Rothschild family

Cinema of Italy