Entity Framework Link Database settings

Source: Internet
Author: User

I am not, learning entityframwork at the same time make a record for everyone to reference. Not much to say directly on the steps

1, add the following code snippet in Webconfig

1 <connectionStrings>22     <add name="defaultconnection " connectionstring="Data source=.; Initial catalog=efmodel;integrated security=false; User Id=sa; Password=sa; Connect timeout=1440; Pooling=true; Multipleactiveresultsets=true; " providername="System.Data.SqlClient "/>33   </connectionStrings>

2. Add a database context and inherit DbContext

1  Public classefdbcontext:D Bcontext2     {3          PublicEfdbcontext ()4:Base("defaultconnection")5         {6         }7 8          PublicDbset<customers> Customer {Get;Set; }9 Ten          PublicDbset<company> Company {Get;Set; }  One}

Note: The name inside the base in the database context is the same as the name of the Webconfig link string

Entity Framework Link Database settings

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.