Please enable JavaScript.
Coggle requires JavaScript to display documents.
ASP.NET Core Fundamentals (Project Structure (EntityFramework…
ASP.NET Core Fundamentals
Project Structure
Program.cs
Tipical code as a console application.
Main - builds a WebHost and tells the WebHost to start running.
VisualStudio will run the WebHost behind IIS Express.
IIS Express acts as a proxy server that forwards requests into the apllication. The application is a separate process and has it's own Web Server and the server is configured inside BuildWebHost method
IWebHost
Will use Kestrel web server (ships as asp.net core, runs on all platforms and listen for HTTP requests)
Startup.cs
Configures how the application behaves
Methods
ConfigureServices
IServiceCollection - DI container
Configure
Pages
Shared
_Layout.cshtml
contains the layout of the application and the main frame
cshtml
@ - allows us to write c# code
Model
- allows us to access properties from the viewmodel
Forms
get vs post
GET Pros:
should be used when fetching data from the server
Cons
a GET operation should not be intended to update or create a record because parameters are displayed in the query string.
also the link could be bookmarked and clicking on the bookmark link could update the records without intent considering a payment operation
POST Pros:
parameters are added to the request body
PRG pattern - POST - REDIRECT - GET
Model Binding
Simple GET
<Input - Search />
HttpContext.Request.QueryString
OnGet(string searchTerm)
OnGet(int searchTerm) - will throw exception because null can't be casted to int
[BindProperty(SupportsGet = true)] - by default works only for POST requests
public string SearchTerm { get; set; }
<input asp-for="SearchTerm" />
Details Page
Table Click
<a href="/Restaurants/Detail?Id=@restaurant.Id" ../>
<a asp-page="./Detail" asp-route-restaurantId="@restaurant.Id" ../>
id vs noId
3 more items...
Edit
4 more items...
Core Components
IConfiguration - allows us to access the appsettings.json
EntityFramework
EntityFrameworkCore
EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Design.
SolveConflicts
DataContext
DbSet<T>
Migrations
dotnet tool install --global dotnet-ef --version 3.0.0
dotnet ef dbcontext list
dotnet ef dbcontext info
SetupConnectionString
Add ConnectionStrings section to appsettings.json
ConfigureServices
services.AddDbContextPool<RestaurantDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("RestaurantDb"));
RestaurantDbContext(DbContextOptions<RestaurantDbContext> options) : base(options)
dotnet ef dbcontext info
error because ConnectionString is on the other project