简体   繁体   English

具有 SQL 服务器凭据的数据库优先实体框架?

[英]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.

相关问题 实体框架 - 混合模型优先和数据库优先方法? - Entity Framework - Mixing model-first and database-first approaches? 实体框架数据库优先方法 Pascal 案例 - Entity Framework database-first approach Pascal case 在数据库优先方法中更新模型实体框架时遇到问题 - having problem with updating model entity framework in database-first approach 具有数据库优先多对多关系问题的实体框架 6 - Entity Framework 6 with Database-First Many to Many relationship problem 是否可以使用数据库优先的Entity Framework 6更新SQLite数据库文件? - Is it possible to update a SQLite database file using Entity Framework 6 in database-first? 实体框架数据库优先:从同一个表中访问 2 个外键名称 - Entity Framework database-first: accessing 2 foreign keys names from same table 具有输出参数和结果集的实体框架数据库优先方法存储过程 - Entity framework database-first approach stored procedure with output parameter and result set 具有数据库优先模型的实体框架 - Entity Framework with Database First model 在 .NET EF 数据库优先中,是否需要 HasIndex()? - In .NET EF database-first, is HasIndex() required? 如何使用Entity Framework将数据添加到SQL Server Express数据库 - How to add data to SQL Server Express database using Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM