mercredi 28 mai 2014

Entity Framework multiple context and Microsoft Azure. How to update database?


Vote count:

0




I have ASP.NET MVC 5 solution with about 4 projects inside. + EF code-first After reading this article I tried to separate application EF context(asp.net identity) from my models context.(both contexts in single database)


Now I have 2 project with different contexts.



//main project
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("MyDB")
{
}
}
//another project
public class DALDbContext : DbContext
{
public DALDbContext()
: base("MyDB")
{
}
...
}


I can update database like this:



update-database -ProjectName:myProject.WEB


update-database -ProjectName:myProject.DAL



(in web i have asp.net identity)


If i will publish this solution from VisualStudio in Azure, i can checking "Execute Code First Migrations (runs on application start).".


enter image description here


But if i understand correct, it will be equivalent only one command:



update-database -ProjectName:myProject.WEB



because it's default project.


I don't understand how to run both command. Other side, I tried to execute both commands separately. I wrote something like that in "Package Manager Console":



Update-Database -ConnectionString "Server=tcp:<server_name>.database.windows.net,1433;Database=<database_name>;User ID=<db_user_name>@<server_name>;Password=<password>;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True;Max Pool Size=100;" -ConnectionProviderName "System.Data.SqlClient"


but i get error: "The ConnectionString property has not been initialized."


Or may be try to run one seed method from another...(but i think it is vary bad)


In the end - 2 question:



  1. Is it a good idea to separate one context from another?

  2. How to run this seeds methods on azure?(or your variant)



asked 50 secs ago






Aucun commentaire:

Enregistrer un commentaire