Handled data by CRUD operations on SQL Azure with EnrityFrameworkCore
- .NET Core SDK installed in your environnement
- VS studio 2019
- Azure account
- Cmder, is optional, instead, you can use the Package Manager Console
Vs studio: Tools > NuGet Package Manager > Package Manager Console
Some commands are:
dotnet new console -o EFCoreTuto
cd EFCoreTuto
after this commands your console application will be created succeeded
To Install EF Core, you install the package for the EF Core database provider you want to target. This tutorial use SqlServer.
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
- You can indicate a specific version in the
dotnet add package
command, using the -v modifier.
See
Get the connection information you need to connect to the database in Azure SQL Database you will need the server name, how create a SQL Server in Azure.
- Get ADO.NET connection information from sql Azure: Once you log in to your azure account, navigate to the database you want to use, under Setting, select Connection strings. Copy the ADO.NET (authentification SQL) connection string
- Config your DbContext: Override a virtual method
OnConfiguring()
from DbContext see EFCoreTuto/EFCoreContext.cs. Check if your database is availabe and can be connected to, usedotnet run
command to start your console. Befor you need to add same test in your class program. you need to allow access your client address IP to open connection, in overview database azure page, set server firewall, Add client IP.
The migrations features in EF Core provide a way to incrementally update the database schema to keep it in sync with the application data model while preserving existing data in the database. Migration inclides command-line tools, see bellow same commande-line to generate your first migration.
If using EF Core 3.x you must be installed
dotnet ef
commande-line as a global or local tool. Most developers will installdotnet ef
as a global
`dotnet tool install --global dotnet-ef`
`dotnet add package Microsoft.EntityFrameworkCore.Design`
`dotnet ef migrations add InitialCreate`
`dotnet ef database update`