Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views16 pages

Tutorial Core Database

Uploaded by

Malak bounejra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views16 pages

Tutorial Core Database

Uploaded by

Malak bounejra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Tutorial Core Database

Connection de l’application à la base de


données

First, You Should Install the following Nugets Package

Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Second, you should paste this in the console

Scaffold-Dbcontext "Server=name_of_you_server;
Database=name_of_your_database; Trusted_Connection=True;
TrustServerCertificate=True;" Microsoft.EntityFrameworkCore.SqlServer -O Models
-f
Third

You Should Add the Following Code

In Appsettings.json

"ConnectionStrings": {
"gestionAeroportContextConnection":
"Server=Your_Server;Database=Your_database;Trusted_Connection=True;Multiple
ActiveResultSets=True;TrustServerCertificate=True;"

In Program.cs

builder.Services.AddDbContext<NameOftheDBContextClass>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("gestionAeroport
ContextConnection ")));
Création des controllers

Next, you should add a controller for each table


Run you application
Login & Registration

Select the project > Right-click > Add > Click on the New Scaffold item.
Select Identity and click on add.
Now select the layout page, as we want authentication. Select all as shown below
provide the DbContext class and click on Add.
Génerer la solution

In order to add support to the razor pages, we have to call the functions in
program.cs

builder.Services.AddRazorPages();

app.MapRazorPages();
In program.cs add
builder.Services.AddDbContext<YourDB_Context>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("gestionAeroport
ContextConnection")));

Dans la console
add-migration -context yourDB_context

update-Database -context yourDB_context

add this in the layout.cshtml <partial name="_LoginPartial" />


Run you application and add a new user
In your database you will find that a new user is added

You might also like