A Preliminary Study on the link in EntityFramework and a preliminary study on Chinese Mythology

Source: Internet
Author: User

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 ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.