Originally thought that already will, but when hands-on found many problems or vague, is so-called above his business. can only re-check the information, and then review again.
vs.net2013 Ef6 mvc5 sqlserver2008
I. Establishment of a database Blogging
Second, create the table, insert test data
CREATE TABLE [dbo]. [Blogs]
(
[BlogId] INT IDENTITY (1, 1) not NULL,
[Name] NVARCHAR (+) NULL,
[URL] NVARCHAR (+) NULL,
CONSTRAINT [Pk_dbo. Blogs] PRIMARY KEY CLUSTERED ([BlogId] ASC)
);
CREATE TABLE [dbo]. [Posts]
(
[PostID] INT IDENTITY (1, 1) not NULL,
[Title] NVARCHAR (+) NULL, [Content] NTEXT null,
[BlogId] INT not NULL,
CONSTRAINT [Pk_dbo. Posts] PRIMARY KEY CLUSTERED ([PostID] ASC),
CONSTRAINT [Fk_dbo. Posts_dbo. Blogs_blogid] FOREIGN KEY ([BlogId]) REFERENCES [dbo]. [Blogs] ([BlogId]) on DELETE CASCADE);
INSERT into [dbo]. [Blogs] ([Name],[url])
VALUES (' The Visual Studio Blog ', ' http://blogs.msdn.com/visualstudio/');
INSERT into [dbo]. [Blogs] ([Name],[url])
VALUES ('. NET Framework Blog ', ' http://blogs.msdn.com/dotnet/');
The tables in the database are as follows:
The above is an example of an existing database that will be used in the current state Codefirst
The primary foreign key is created using cascade Delete, which is later changed to soft Delete, so it will not be used.
Iii. Creating solutions and projects
Iv. installation of the new EF
V. Adding a data Entity object
Vi. generated context and entity objects
Connection string generated in Web. config
Vii. adding attributes to a blog entity object
Vii. test-generated entity objects
When the project is established, if the authentication method is not selected, the system does not import files such as validation js, and it needs to be copied into the project manually.
At this point, the base part of the Codefirst based on the existing database has been completed and tested.
This article refer to http://msdn.microsoft.com/zh-cn/data/jj200620
This article and the original copyright all belong to the above author all
EF6 in the original database use Codefirst Total review (first, build the basic environment)