Bright Leopold

i come from the other world,i will go back after the love,the regret,the alive and the dead are over

导航

EF4.1DbContext使用现成的数据库

在配置文件中使用

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


}

posted on 2014-06-18 22:37  Bright Leopold  阅读(239)  评论(0编辑  收藏  举报