How can I create a database schema dynamically using Entity Framework in Azure SQL Database?

Basically, I have a DBContext in my application, but my application will be multi-user, which means we need to create a separate database for each of our clients to isolate the data from each other.

I found this example for creating a DB on Azure https://code.msdn.microsoft.com/windowsazure/How-to-create-a-Azure-SQL-5157ce03

static void Main(string[] args) 
      { 

          SqlManagementClient client = new SqlManagementClient(getCredentials()); 
     //Server Name is your SQL Azure DataBase server name, for example:da0dt6hrt6 
          client.Databases.Create("{Server-Name}", new Microsoft.WindowsAzure.Management.Sql.Models.DatabaseCreateParameters() 
          { 
              Name = "OnecodeTest", 
              MaximumDatabaseSizeInGB = 1, 
              CollationName = "SQL_Latin1_General_CP1_CI_AS", 
              Edition="Web" 
          }); 

          Console.ReadLine(); 
      } 

      

However, I do not know how to programmatically create my CODE FIRST model in this new database.

this is my appdatacontext

public class AppDataContext : DbContext
    {

        public AppDataContext() : base("AppDataContext")
        {
        }

        public DbSet<Module> Modulos { get; set; }

        public DbSet<Empresa> Empresas { get; set; }

        public DbSet<Entidad> Entidades { get; set; }

        public DbSet<Propiedad> Propiedades { get; set; }

        public DbSet<ModulosPorUsuario> ModulosPorUsuario { get; set; }

        public DbSet<PerUserWebCache> PerUserCacheList { get; set; }


        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }

    }

      

+3
c # sql-server asp.net-mvc ef-code-first azure-sql-database


source to share


No one has answered this question yet

Check out similar questions:

907
How can I execute an UPDATE statement with JOIN in SQL?
515
How can I get the ID of the inserted entity in the Entity framework?
115
How do I recreate the database for Entity Framework?
2
Dynamic Database / Schema in Entity Infrastructure for Windows Azure / SQL Azure
1
How do I create a database in Azure?
1
Entity Framework 5 CF Firebird - same code creates different queries
1
how to connect azure database in sql server
0
How do I connect to a federated Azure database and apply federation on the DBContext entity structure?
0
Programmatically creating a connection string to map an Entity Framework Code-First model to an existing Azure Sql database
0
Mapping Variables to an Azure SQL Database Table



All Articles
Loading...
X
Show
Funny
Dev
Pics