Http://www.cnblogs.com/dudu/archive/2011/01/29/entity_framework_connection_string.html
The connection string used by Entity Framework is different from that used by ADO. net. For details, see:
Compared with ADO. net, the connection string of Entity Framework not only stores metadata configuration information, but also stores the complete database connection string (in the "provider connection string" section ).
This design has two shortcomings:
1. The connection string configuration is complex;
2. Existing ADO. NET database connection strings cannot be reused.
I think a more reasonable design should be to separate the database connection string and provide a "provider connection string name" setting. In this setting, you can specify the name of "database connection string, see:
This is simple and reusable!
After YY, I still want to return to reality. Entity Framework is just like this. I just want to reuse the existing database connection string. What should I do?
Create your own entityconnection and pass it to the objectcontext constructor,CodeAs follows:
Public Cnblogsobjectcontext ()
: Base (Buildconnection ( " Cnblogsdb " ), " Club_cnblogscontainer " )
{
}
Static Entityconnection buildconnection ( String Connectionstringname)
{
String Connectionstring = Configurationmanager. connectionstrings [connectionstringname]. connectionstring;
Metadataworkspace = New Metadataworkspace ( New String [] { " Res ://*/ " },
New Assembly [] {assembly. getexecutingassembly ()});
Sqlconnection = New Sqlconnection (connectionstring );
Return New Entityconnection (workspace, sqlconnection );
}
The connection string used by Entity Framework is different from that used by ADO. net. For details, see:
Compared with ADO. net, the connection string of Entity Framework not only stores metadata configuration information, but also stores the complete database connection string (in the "provider connection string" section ).
This design has two shortcomings:
1. The connection string configuration is complex;
2. Existing ADO. NET database connection strings cannot be reused.
I think a more reasonable design should be to separate the database connection string and provide a "provider connection string name" setting. In this setting, you can specify the name of "database connection string, see:
This is simple and reusable!
After YY, I still want to return to reality. Entity Framework is just like this. I just want to reuse the existing database connection string. What should I do?
Create your own entityconnection and pass it to the objectcontext constructor. The Code is as follows:
Public Cnblogsobjectcontext ()
: Base (Buildconnection ( " Cnblogsdb " ), " Club_cnblogscontainer " )
{
}
Static Entityconnection buildconnection ( String Connectionstringname)
{
String Connectionstring = Configurationmanager. connectionstrings [connectionstringname]. connectionstring;
Metadataworkspace = New Metadataworkspace ( New String [] { " Res ://*/ " },
New Assembly [] {assembly. getexecutingassembly ()});
Sqlconnection = New Sqlconnection (connectionstring );
Return New Entityconnection (workspace, sqlconnection );
}