[英]Database-First Entity Framework with SQL Server credentials?
Does anyone know of any way in which a database-first Entity Framework dbcontext can be implemented using SQLCredential?有谁知道可以使用 SQLCredential 实现数据库优先实体框架 dbcontext 的任何方式? (you cannot pass a new
SqlConnection
with an allowable connection string - they are rejected). (您不能通过允许的连接字符串传递新的
SqlConnection
- 它们被拒绝)。
Code-first will allow this, but not database-first.代码优先将允许这样做,但不允许数据库优先。 Basically, I can't create a database-first connection string that allows a new
SqlConnection
to instantiate correctly nor do I have decrypted credentials available to me.基本上,我无法创建允许新
SqlConnection
正确实例化的数据库优先连接字符串,也无法解密可用的凭据。 I am completely open to ideas.我对想法完全开放。
Sample (model exists in dll, as database-first):示例(模型存在于 dll 中,作为数据库优先):
public partial class Entities : DbContext
{
public Entities(string connStr, SqlCredential creds)
: base(new SqlConnection(connStr, creds), true)
{
}
The answer is: No, you can't.答案是:不,你不能。 Because entity framework doesn't use sqlclient namespace internally and inherits from Common instead.
因为实体框架内部不使用 sqlclient 命名空间,而是从 Common 继承。 The only way to do it is a string replace method in the connection string itself.
唯一的方法是在连接字符串本身中使用字符串替换方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.