Now I'm starting to learn EF. I want to use EF code to create new tables in SQL Azure.
Here is my code:
namespace WebApplication2 { public class Blog { public int UserName { get; set; } public int ID { get; set; } } public class BlogContext : DbContext { public DbSet<Blog> Blogs { get; set; } public BlogContext() : base("MYEF") { } } }
Code behind:
protected void Page_Load(object sender, EventArgs e) { using (var db = new BlogContext()) { var blog = new Blog { UserName = 456 }; db.Blogs.Add(blog); db.SaveChanges(); } }
Web.config :
<connectionStrings> <add name="TestDBContext" connectionString="Server=tcp:mydb.database.windows.net,1433;Database=MYEF;User ID=[Username];Password=[MyPassword];Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True" providerName="System.Data.SqlClient" /> </connectionStrings>
When I check my Azure SQL database, the table was not created, EF still creates the MYEF table in the default SQL Server Express database.
Has anyone done this successfully?
source share