The Entirtyframework framework is a lightweight, extensible version of the popular Entity Framework data access technology.
One of them. Netcore version corresponds to Entityframeworkcore
Git source code address: https://github.com/aspnet/EntityFramework/
Official Use document Description: Https://docs.microsoft.com/zh-cn/ef/core/index
First, install the NuGet package
install-Packagemicrosoft.entityframeworkcoreinstall-package Microsoft.EntityFrameworkCore.SqlServer
Core package of the Micorsoft.EntityFrameworkCore:EF framework
Micorsoft.EntityFrameworkCore.SqlServer: For SQL Server database extensions, the SQL Server database must be used. Similar to Mysql,sqllite and so on.
Micorsoft.EntityFrameworkCore.Tools
&micorosft.entityframeworkcore.design: The user generates the model code based on the existing database, and more reference: https://docs.microsoft.com/zh-cn/ef/ Efcore-and-ef6/porting/port-edmx
Ii. Examples of Use
1. After installing the NuGet package, manually create the context and inject the SQL link string
usingMicrosoft.entityframeworkcore;namespacecore2{ Public classTestcontext:dbcontext {//Public TestContext (dbcontextoptions<testcontext> options): Base (options)//{ //} protected Override voidonconfiguring (Dbcontextoptionsbuilder optionsbuilder) {//inject SQL link stringOptionsbuilder.usesqlserver (@"server=.;D Atabase=test1; Trusted_connection=true;"); } PublicDbset<numeber1> Numeber1s {Get;Set; } }}
2. Handwritten entity classes, as long as there is a corresponding table in the database can be
usingSystem.ComponentModel.DataAnnotations;usingSystem.ComponentModel.DataAnnotations.Schema;namespacecore2{[Table ("Numeber1")] Public classNumeber1 {[Key] Public intID {Get;Set; } Public decimalNUM1 {Get;Set; } }}
3. Test the code:
Static voidTestone () {TestContext _context=NewTestContext (); intCount =_context. Numeber1s.count (); Console.WriteLine (count);}Static voidTesttwo () {DateTime start=DateTime.Now; TestContext _context=NewTestContext (); for(inti =0; I <10000; i++) {_context. Numeber1s.add (NewNumeber1 () {Num1=i}); _context. SaveChanges (); } Console.WriteLine (_context. Numeber1s.count ()); Console.WriteLine ("total time, number of seconds:"+ (DateTime.Now-start). totalseconds);}
10,000 insert Data Execution time in debug state:
Third, based on the database generation model
1. Installing Entityframeworkcore.design and Entityframeworkcore.tools
2. Select the corresponding project, perform the generation naming
" server=.; Database=test1; Trusted_connection=true; " Microsoft.entityframeworkcore.sqlserver-outputdir MODELS2
3. The resulting results are as follows:
More:
VS code build. Netcore Development Environment (II)
VS code build. Netcore Development Environment (i)
Chocolatey Introduction (software Automation management tools)
. The use and finishing of Efcore in Netcore