在配置文件中使用
<configuration>
<connectionStrings>
<add name="BlogDB" providerName="System.Data.SqlClient"
connectionString="Data Source=.\sqlexpress;Initial Catalog=MyBlogDB;Integrated Security=True"/>
</connectionStrings>
</configuration>
标记name=BlogDB的连接字符串
然后在DbContext的子类中使用
public class BlogDbContext : DbContext
{
public BlogDbContext()
: base("name=BlogDB")
{ }
public IDbSet<BlogUser> BlogUsers { get; set; }
public IDbSet<Post> Posts { get; set; }
}