A Preliminary Study on the link in EntityFramework and a preliminary study on Chinese Mythology
Many people use the default link factory of EF: System. Data. Entity. Infrastructure. LocalDbConnectionFactory.
Then I was not used to it at the beginning, and I studied it as follows:
Then
Public System. Data. Common. DbConnection CreateConnection (string nameOrConnectionString)
System. Data. Entity. Infrastructure. LocalDbConnectionFactory Member
Abstract:
Create a connection for SQL Server LocalDb Based on the given database name or connection string. If the given string contains the "=" character, it is considered a complete connection string; otherwise, it is considered only the database name.
Parameters:
NameOrConnectionString: Database Name or connection string.
Return Value:
The initialized DbConnection.
This is why [name = Database Link name] can be used.
Most people use their own Dbcontext names when using Model frist and db frist.
Next
BaseConnectionString in SqlConnectionFactory
Public string BaseConnectionString {get ;}
System. Data. Entity. Infrastructure. SqlConnectionFactory Member
Abstract:
The connection string used for the options of the database outside the "Initial directory. When CreateConnection is called, the "Initial directory" is pre-configured based on the database name before this string ". The default value is "Data Source =. \ SQLEXPRESS; Integrated Security = True; MultipleActiveResultSets = True ".
Return Value:
The connection string.
BaseConnectionString, a member in LocalDbConnectionFactory
Public string BaseConnectionString {get ;}
System. Data. Entity. Infrastructure. LocalDbConnectionFactory Member
Abstract:
The connection string used for database options other than "Initial directory", "Data Source", and "AttachDbFilename. When CreateConnection is called, "Initial directory" and "AttachDbFilename" are added before the string based on the database name ". Set "Data Source" based on the LocalDbVersion parameter ". The default value is "Integrated Security = True; MultipleActiveResultSets = True ;".
The default values are different.
I used EF4.4 and found three linked factories,SqlConnectionFactory,LocalDbConnectionFactory, SqlCeConnectionFactory. The last one is for small databases such as SqlCE and Access.
In this way, the database is automatically created, and the default database (pitfall) is not included in many articles ).