I thought it was done now. But I found many problems are still vague. You can only review the information and review it again.
Vs. net2013 ef6 mvc5 sqlserver2008
1. Create Database Blogging
2. Create a table and insert Test Data
Create table [dbo]. [Blogs]
(
[BlogId] int identity (1, 1) not null,
[Name] NVARCHAR (200) NULL,
[Url] NVARCHAR (200) NULL,
CONSTRAINT [PK_dbo.Blogs] primary key clustered ([BlogId] ASC)
);
Create table [dbo]. [Posts]
(
[PostId] int identity (1, 1) not null,
[Title] NVARCHAR (200) 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 preceding example shows the original database. CodeFirst is used in the current status.
Cascade Delete is used when the primary and Foreign keys are created. It will be changed to soft Delete later, so it will not be used.
3. create solutions and projects
4. Install the new EF version
5. Add Data Object
6. generated context and Object
Connection string generated in web. config
7. Add features for Blog object
7. Test the generated object
When you create a project, if you select none as the authentication method, the system does not import files such as verify js, You need to manually copy them into the project.
So far, the basic part of CodeFirst based on the existing database has been completed and passed the test.
This article references http://msdn.microsoft.com/zh-cn/data/jj200620
The copyright of this article and the original article belongs to the aforementioned author.