c# - 如何创建指定数据库类型的 DbContext 实例
问题描述
我知道这里默认返回的是SQL Server数据库类型,但是我需要MySQL数据库类型,问题是创建DbContext
指定数据库类型的实例?
当然我知道也可以通过指定 来创建connectionName
,但是数据库连接字符串是加密的,字符串需要解密
伪代码如下:
public partial class MyDbContext : DbContext
{
static string mysqlConn = ReadConnectionString(); //Get the encrypted MySQL connection string
public MyDbContext() : base(mysqlConn)
{
// Even if I want to modify the connection string in this way, nor will it throw a connection string malformed exception
Database.Connection.ConnectionString = DecryptConnectionString(mysqlConn);
}
}
解决方案
Ok, it's about what I expected, few of my questions can be answered.
Although I am not too familiar with EntityFramework, by looking at the source code of DbContext, I can almost certainly determine that this is a design flaw, it lacks a constructor like this:
Public DbContext(string connectionString, string providerName)
推荐阅读
- string - 没有得到打印的“模式”字符串的“计数”。这是代码
- ios - 结构错误:QuartzCore (CA::Layer::set_bounds(CA::Rect const&, bool))
- java - Moshi 用于解析 Youtube Search Api
- typescript - 期望(路径).to.be.a.file()无法编译“类型'TypeComparison'上不存在属性'文件'”
- firebase-realtime-database - 如果我升级我的 Firebase 计划,情况是否解决了?
- c++ - 如何逐步更新 QMainWindow?
- azure - 如何在 Web App 上配置 IP 限制以仅允许通过应用程序网关的流量?
- python - AttributeError: '_io.TextIOWrapper' 对象没有属性 'append'
- javascript - 将对象数组减少到 x 个项目。试图保留至少 2 个特定对象属性值
- c# - 按升序排列列表框