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="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 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!