使用EnityFramework时,如何将指定字符串用作将连接到数据库的名称或者连接字符串名称

1     public class EFDbContext : DbContext
2     {
3         public EFDbContext()
4             : base("name=MySqlCon")//这里可以指定web.config中连接数据库字符串的name值
5         { }
6     }

如:

  <connectionStrings>
    <add name="MySqlCon" providerName="System.Data.SqlClient" connectionString="server=.;uid=sa;pwd=sa;database=test;"/>
  </connectionStrings>

同时,要记得添加 System.Data.Entity.dll 引用。

posted @ 2015-01-03 16:42  Zero#  阅读(141)  评论(0编辑  收藏  举报