Project Address: https://gitee.com/dhclly/IceDog.EFCore
Project Introduction
For practice tests Microsoft EntityFramework Core Framework
Reference Documentation Tutorials
- Official documents entrance https://docs.microsoft.com/zh-cn/ef/core/
- Razor Pages with Entity Framework Core in ASP.NET Core https://docs.microsoft.com/zh-cn/aspnet/core/data/ef-rp/intro?view=aspnetcore-2.2&tabs=visual-studio
- Entity Framework Core 2.0 Getting Started Demo https://github.com/stulzq/EntityFrameworkCore2Demo
- Entity Framework Core 2.0 Getting started http://www.cnblogs.com/stulzq/p/7717873.html
- Entity Framework Core 2.0 New Features http://www.cnblogs.com/stulzq/p/7366044.html
- Core learning step by step EF (1.DBFirst) https://www.cnblogs.com/GuZhenYin/p/6857413.html
- Entity Framework Code First (一) https://www.cnblogs.com/panchunting/p/entity-framework-code-first-conventions.html
- Contoso University https://docs.microsoft.com/zh-cn/aspnet/core/data/ef-rp/intro?view=aspnetcore-2.2&tabs=visual-studio
Project Description
IceDog.EFCore.Cmd.CodeFirst
This is an example of a project EFCore Code First, details which projects inside the readme
disposed in the connection string IceDog.EFCore \ src \ IceDog.EFCore.Cmd \ Context \ BloggingContext.cs
IceDog.EFCore.Cmd.DBFirst
This is a EFCore DB First sample project, the details of the project readme inside inside
IceDog.EFCore.Cmd.OfficalDemo
This project is an example of Microsoft's official quick start my practice, for your reference, the details of the project inside the readme inside.
Official Tutorial Address: https://docs.microsoft.com/zh-cn/ef/core/
IceDog.EFCore.WebApiServer
This is EF Core WebApi in different projects inside the application, and general project lies in the configuration database connection is not Context inside, but in
IceDog.EFCore\src\IceDog.EFCore.WebApiServer\Startup.cs
Inside ConfigureServices
Inside
Details of the project inside the readme inside
IceDog.EFCore.ContosoUniversity
This project is to achieve the following contents of the document, the official can see tutorials
ASP.NET Core Razor pages and EF Core - tutorial series
https://docs.microsoft.com/zh-cn/aspnet/core/data/ef-rp/?view=aspnetcore-2.2
Reference Code https://github.com/aspnet/Docs/tree/master/aspnetcore/data/ef-rp/intro/samples
Details of the project inside the readme inside
Commonly used EF Core drive
The following drivers can be found in nuget, MySql / MariaDB recommended Pomelo EF Core components because the official is currently possible bug, Pomelo EF Core Microsoft officials also recommended.
The official recommendation list Address: https://docs.microsoft.com/zh-cn/ef/core/providers/index
- SqlServer:Microsoft.EntityFrameworkCore.SqlServer
- MySql:Pomelo.EntityFrameworkCore.MySql
- Oracle:Oracle.ManagedDataAccess.Core Citms.EntityFrameworkCore.Oracle
- SqlLite:Microsoft.EntityFrameworkCore.Sqlite
EF relevant directives
Add to migrate merged version
Add-Migration v1.0.0 -o Migrations
Add-Migration v1.0.1 -o Migrations
The new directive
Into the project folder inside the execution (the directory containing the .csproj file)
dotnet ef migrations add v1.0.0
dotnet ef migrations add -p "ConsoleApp.SQLite.csproj"#和上面等效
dotnet ef migrations add --project "ConsoleApp.SQLite.csproj"#和上面等效
dotnet ef migrations add -s "ConsoleApp.SQLite.csproj"#和上面等效
dotnet ef migrations add --startup-project "ConsoleApp.SQLite.csproj"#和上面等效
Remove merge
Remove-Migration
The new directive
dotnet ef migrations remove
Migrating display version list
dotnet ef migrations list
Update the database
Update-Database
The new directive
dotnet ef database update
Delete library instruction
Drop-Database
The new directive
dotnet ef database drop
If the case can not occur with the command, enter the following command console Package Manager
Import-Module C:\Users\Administrator\.nuget\packages\microsoft.entityframeworkcore.tools\2.1.0\tools\EntityFrameworkCore.psd1
If you execute the above command appears Build failed.
The reason is that there are solutions for many types of applications, leaving only one type, the other can to uninstall, such as a project which contains a console project and webapi project, even if the console is set to start the project, but when activated or will launch a Web project, leading to a build fails.
QA
1. Perform Add-Migration init
error Add-Migration: Can not "Add-Migration" item identifies the name of a cmdlet, function, script file or run a program. Please check the spelling of the name, if you include a path, make sure the path is correct, and then try again. How to solve?
1, compile the project. After you first EF Core in the project, this step must be done, otherwise you can not find the follow-up EntityFrameworkCore.psd1 module to import.
2, find the location of the file, using the import command Import-Module. I am here:
Import-Module C:\Users\Administrator\.nuget\packages\microsoft.entityframeworkcore.tools\2.1.0\tools\EntityFrameworkCore.psd1
Implementation of information is as follows:
Module "EntityFrameworkCore" in the name of the import command contains certain unapproved verbs, verbs could cause the commands were difficult to detect. To find the command has not approved verbs, use the Verbose parameter run Import-Module command again. To approve a list of verbs, type Get-Verb.
Then you can normally use the command.
2. Perform Add-Migration
, Update-Database
appear build failed
how to do?
https://stackoverflow.com/questions/44785540/ef-core-add-migration-build-failed
The reason is that there are solutions for many types of applications (project which contains Migrations), leaving only one type, the other can to uninstall, such as a project which contains a console project and webapi project,
even if it is set up console to start the project, but the start time or will launch a Web project, leading to a build fails.
Of course, why did not fail and do not tangle, and without fail better
3. Use sqllite time, vs Debugging Tips table does not exist how to do?
From the Visual Studio run this example, you must manually set the working directory to the root directory of the project. If the working directory is not set, it will lead to the following
Microsoft.Data.Sqlite.SqliteException
:SQLite Error 1: 'no such table: Blogs'
.Set the working directory:
- In the "Solution Explorer", right-click the project and select "Properties."
- Select the "Startup" tab in the left pane.
- Set the working directory to the project directory.
- save Changes.
Links: https://docs.microsoft.com/zh-cn/ef/core/get-started/netcore/new-db-sqlite#vs
Additional
Since the test using mysql, and therefore the need to introduce Pomelo.EntityFrameworkCore.MySql v2.1.2 .
In fact, for console project, the need to introduce nuget package, Microsoft.EntityFrameworkCore.Design , this time to introduce version is v2.1.4.
For a Web project, you need to install Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Relational , this time installed version is v2.1.4.
Otherwise, perform the following Entity Framework Core Tools command error, suggesting that the missing dependencies above.
Study documents Address: https://gitee.com/dhclly/icedog.script.test/tree/master/doc/dot-net/dot-net-core/entity-framework-core