SimpleMembership和Entity Framework可以共享一个连接字符串吗? [英] Can SimpleMembership and Entity Framework share a connection string?
问题描述
当前使用Entity Framework和SimpleMembership时,我需要在 web.config
中具有2个连接字符串。
第一个在调用 WebSecurity.InitializeDatabaseConnection
及其简单的连接字符串时使用。另一个用于edmx,包含文件引用和连接字符串信息。这意味着连接字符串信息在文件中两次。
除了复制信息外,我相信使用天蓝色(未经证实)也可能是一个问题。
有没有一种方法可以将其简化为一个连接字符串,而仅将其保留给edmx使用。仅仅将EF一个传递给WebSecurity初始化方法是行不通的。区别在于edmx的连接字符串包含该模型的额外元数据。
最好的选择是仅拥有edmx连接字符串,然后使用 EntityConnectionStringBuilder 。
var builder =新的EntityConnectionStringBuilder(entityConnectionString);
字符串sqlConnString = builder.ConnectionString;
然后使用该连接字符串初始化SimpleMembershipProvider
WebSecurity.InitializeDatabaseConnection(sqlConnString, User, UserId, UserName,autoCreateTables:true);
Currently when using Entity Framework and SimpleMembership I need to have 2 connection strings in web.config
.
The first is used when calling WebSecurity.InitializeDatabaseConnection
and its a simple connection string. The other is for the edmx and contains file references and the connection string info. It means the connection string info is in the file twice.
As well as duplicating information, I believe it can be an issue using azure (unconfirmed).
Is there a way to reduce this to one connection string and just keep the one for the edmx. Simply passing the EF one to the WebSecurity initialization method does not work.
Yes you can use the same connection string for both. The difference is that the connection string for the edmx contains extra metadata for the model.
Best bet would be to just have the edmx connection string, then parse it with the EntityConnectionStringBuilder.
var builder = new EntityConnectionStringBuilder(entityConnectionString);
string sqlConnString = builder.ConnectionString;
Then initialise SimpleMembershipProvider with that connection string
WebSecurity.InitializeDatabaseConnection(sqlConnString, "User", "UserId", "UserName", autoCreateTables: true);
这篇关于SimpleMembership和Entity Framework可以共享一个连接字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!