您的位置:首页 > 博客中心 > 数据库 >

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

时间:2022-03-14 04:31

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 引用。

热门排行

今日推荐

热门手游