There are three modes for the development of the entity Framework Data Model: 1. Reference database mode; 2. New EF empty model mode in VS; 3. Code mode
The Entity Framework data model refers to the use of the Reference database method for development creation, as follows:
Development environment: VS2012
Database: SQL Server 2008
Entity Framework Version: 6.12
1. Create a new database
Create a new database in the database and make a data table, the following is for reference only:
2. New Project
Create a new console application in VS Future.LifeWillBetter.DAL.ForDBConsoleApplication
3. New Data Model
Right-click future.lifewillbetter.dal.fordbconsoleapplication-"Add-" New item
Click "New Connection", which is a connected database, then locate the data you just created and select the
Click OK, and when you are done, go directly to the next step.
Direct next.
, of course, you can select the view, the stored procedure, and then click Finish.
A FUTURELIFEWILLBETTERDALFORDBMODEL.EDMX data model is then generated,
4. Data Model Extension use
It is not possible to add new data tables or stored procedures and views in development, so know how to expand!
① I'm in the database Future.lifewillbetter, create a new table
CREATE TABLE [dbo]. [T_comments] ( [Id] [int] IDENTITY (1,1) not NULL, [ArticleID] [int ] NULL, [authorname] [nvarchar] () null, [Contents] [nvarchar] (max) null, [ PubDate] [datetime] NULL ) GO
In this case, my data sheet is new and the next step is to update our FUTURELIFEWILLBETTERDALFORDBMODEL.EDMX data model.
Double-tap Open futurelifewillbetterdalfordbmodel.edmx Right-click in the blanks, from the database update model
Click OK to see a form that just started selecting datasheets, views, stored procedures ...
I check all, then click Done, After clicking Finish, remember to save the data model file: FUTURELIFEWILLBETTERDALFORDBMODEL.EDMX; So we can futurelifewillbetterdalfordbmodel.edmx this data model Futurelifewi Llbetterdalfordbmodel.tt See a T_comments entity class;
This is our new data sheet, of course, if we delete the data table we can also delete the entities in the data model in the same way.
5. Data model, Document introduction
①app.config: Configuration file, which already contains basic information such as database links for Entity data
<?xml version="1.0"encoding="Utf-8"?><configuration> <configSections> <!--for more information on Entity Framework configuration, Visi T 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=" Data source=.; Initial catalog=future.lifewillbetter;integrated security=true; Multipleactiveresultsets=true; app=entityframework""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 Entity Data Model (FUTURELIFEWILLBETTERDALFORDBMODEL.CONTEXT.TT)
③FUTURELIFEWILLBETTERDALFORDBMODEL.TT: This contains specific entities (that is, classes in database tables)
Look again at the directory structure:
Finish!
Entity Framework Learning Note (i) Data model database