EntityFramework Database Configuration (Code frist)

Source: Internet
Author: User

I'm not saying anything. Post Code First

<?xml version= "1.0" encoding= "Utf-8"?><configuration>  <configSections>    <!--for more Information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/? linkid=237468--    <section name= "EntityFramework" type= " System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=4.4.0.0, Culture=neutral, publickeytoken=b77a5c561934e089 "requirepermission=" false "/>  </configSections>  < entityframework>    <defaultconnectionfactory type= " System.Data.Entity.Infrastructure.LocalDbConnectionFactory, entityframework ">      <parameters>        <parameter value= "v11.0"/>      </parameters>    </defaultConnectionFactory>  </ Entityframework></configuration>

<?xml version= "1.0" encoding= "Utf-8"?><configuration> <configSections> <!--for more information On Entity Framework configuration, visit http://go.microsoft.com/fwlink/? linkid=237468--<section name= "EntityFramework" type= " System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=4.4.0.0, Culture=neutral,    publickeytoken=b77a5c561934e089 "requirepermission=" false "/> </configSections> <connectionStrings> <add name= "entitycontextentities" connectionstring= "metadata=res://*/model1.csdl|res://*/model1.ssdl|res://*/ Model1.msl;provider=system.data.sqlclient;provider connection string= "Data source=.; Initial catalog=entitycontext;integrated security=true; Multipleactiveresultsets=true; App=entityframework "" Providername= "System.Data.EntityClient"/> </connectionStrings> <entityframework > <defaultconnectionfactory type= "System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework "> <parameters> <parameter value=" v11.0 "/> <!--<parameter value=" Data so Urce=.;i ntegrated security=true "/>--> </parameters> </defaultConnectionFactory> &LT;/ENTITYFRAMEWORK&G T;</configuration>

The above is my configuration is the problem, I was using the default database connection test

In EF I saw roughly three kinds of database connection factory, I used localdbconnectionfactory and sqlconnectionfactory, these two have some differences in configuration, and the default configuration cannot specify the database name

<?xml version= "1.0" encoding= "Utf-8"?><configuration> <configSections> <!--for more information On Entity Framework configuration, visit http://go.microsoft.com/fwlink/? linkid=237468--<section name= "EntityFramework" type= " System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version=4.4.0.0, Culture=neutral, publickeytoken=b77a5c561934e089 "requirepermission=" false "/> </configSections> <entityFramework> & lt;! --<defaultconnectionfactory type= "System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework "> <parameters> <parameter value=" v11.0 "/> <parameter value=" Data source=.;i Nitial Catalog=entitycontext; User Id=sa; password=123456; Multipleactiveresultsets=true "/> </parameters> </defaultConnectionFactory>--> <defaultcon  Nectionfactory type= "System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" >    <parameters> <!--<parameter value= "v11.0"/>--> <parameter value= "Data source=.;i Nitial Catalog=entitycontext; User Id=sa; password=123456; Multipleactiveresultsets=true "/> </parameters> </defaultConnectionFactory> &LT;/ENTITYFRAMEWORK&G  T <connectionStrings> <add name= "Entitycontext" connectionstring= "Data source=.; Database=entitycontext; User Id=sa; password=123456, "providername=" System.Data.SqlClient "/> </connectionStrings></configuration>

After repeated testing, (the Model Frist and DB Frist database connection information is placed in the connectionstrings tag, code frist is placed in EntityFramework parameter, and the connection string needs to be added

Multipleactiveresultsets=true)
There is the replacement of the System.Data.Entity.Infrastructure.SqlConnectionFactory database factory class,

If using MSSQL, to use sqlconnectionfactory this link library and own name of the database name, and under the <connectionStrings> tag to write the link configuration, the code to determine the name of the connection.

Public Entitycontext ()            : Base ("Name=entitycontext")//This is not a database name, is the name of the link string        {        }

EntityFramework Database Configuration (Code frist)

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.