Microsoft has been on the cross-platform over the last few years, with many. NET programmers gearing up for Microsoft. Just recently, Microsoft has launched the ASP. NET core2.0 Preview.
Through a simple attempt at. NET core, I found that in the past when we developed an MVC project, we created and updated the entity model by creating a new. edmx file, but in the core, Microsoft removed the. edmx, so let's take a look at how the model class is generated in core.
Environment: vs2017 + sqlserver2012
The first step is to create a test library
CREATE DATABASE [Blogging]; Gouse [Blogging]; Gocreate TABLE [Blog] ( [BlogId] int not null IDENTITY, [Url] nvarchar (max) is not NULL, CONSTRAINT [Pk_blog] PRI MARY KEY ([BlogId]); Gocreate TABLE [Post] ( [postid] int not null IDENTITY, [BlogId] int. NOT NULL, [Content] nvarchar (max), [ Title] nvarchar (max), CONSTRAINT [pk_post] PRIMARY KEY ([PostID]), CONSTRAINT [Fk_post_blog_blogid] FOREIGN KEY ([BlogId]) REFERENCES [Blog] ([BlogId]) on DELETE CASCADE); Goinsert into [Blog] (URL) VALUES (' Http://blogs.msdn.com/dotnet '), (' Http://blogs.msdn.com/webdev '), (' HTTP/ Blogs.msdn.com/visualstudio ') GO
Step two Create a. NET Core project
Slightly
Step three Install EF
NuGet Package Manager
Install with NuGet:
Fourth Step creating the entity model from the database
Tools–nuget Package manager– A model the existing. You receive an error stating the term recognized the name a cmdlet,
The project generates a model folder with the entity classes and contexts we need BloggingContext.cs
Complete! Because we only describe how to generate entity classes, so far, if you want to manipulate the entity class additions and deletions, we also need to register the context in the Startup.cs file, specifically, you can refer to Microsoft's documentation:
Https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db