Entity Framework learning notes (1)-data model database, entityframework

Source: Internet
Author: User

Entity Framework learning notes (1)-data model database, entityframework

There are three modes for Developing Entity Framework data models: 1. Reference Database methods; 2. Create an EF empty Model in VS; 3. Code methods.

The Entity Framework Data Model references "reference database method" for development and creation, as follows:

Development Environment: VS2012

Database: SQL Server 2008

Entity Framework Version: 6.12

1. Create a database

Create a database in the database and create a data table. The following is for your reference only:

2. Create a project

Create a new console application Future. LifeWillBetter. DAL. ForDBConsoleApplication in

3. Create a data model

Right-click Future. LifeWillBetter. DAL. ForDBConsoleApplication-> Add-> Create item

 

 

Create table [dbo]. [T_Comments] ([Id] [int] IDENTITY (1,1) not null, [ArticleId] [int] NULL, [AuthorName] [nvarchar] (50) NULL, [Contents] [nvarchar] (max) NULL, [PubDate] [datetime] NULL) GO

In this way, my data table is created successfully. The next step is to update our FutureLifeWillBetterDALForDBModel. edmx data model.

Double-click FutureLifeWillBetterDALForDBModel. edmx and right-click the blank area.

Click "OK". A data table, view, and stored procedure form is displayed. Continue...

Select All and click Finish. After clicking finish, remember to save the data model file FutureLifeWillBetterDALForDBModel. edmx; in this way, we can go to FutureLifeWillBetterDALForDBModel. the FutureLifeWillBetterDALForDBModel of the edmx data model. tt sees a T_Comments object class;

This is a new data table. If you delete a data table, you can delete the entities in the data model in the same way.

5. Data Model, file Introduction

① App. config: configuration file, which contains basic information such as database links of Object Data

<?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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />  </configSections>  <startup>    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />  </startup>  <connectionStrings>    <add name="Entities" connectionString="metadata=res://*/FutureLifeWillBetterDALForDBModel.csdl|res://*/FutureLifeWillBetterDALForDBModel.ssdl|res://*/FutureLifeWillBetterDALForDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=Future.LifeWillBetter;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />  </connectionStrings>  <entityFramework>    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />    <providers>      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />    </providers>  </entityFramework></configuration>

② FutureLifeWillBetterDALForDBModel. Context. cs: Context of the object data model (under FutureLifeWillBetterDALForDBModel. Context. tt)
③ FutureLifeWillBetterDALForDBModel. tt: The following contains specific entities (classes in the unit of database tables)

Check the directory structure again ,:

Complete!

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.