ASP .NET Core MVC with EF And C#
Run console application c# .net6 using ctrl+f5
Compile the application using ctrl+shift+b
What is EF (Entity Framework)?
Entity Framework is a new latest technology provided by ODO.net for accessing databases.
It is an ORM tool (Object Relation Mapping).
It provides an easy and automated way of mapping between objects(Classes) and Relations (Tables).
It auto-generates most of the data-access code.
Why use ORM?
It provides full intellisense support for column names and table names. (Strongly typed).
What is asp.net core?
Cross Platform, High Performance, Open source framework for building modern, cloud-based, internet-connected applications.
- 1. Cross-platform
- 2. Ability to install the features that are needed for the application
- 3. A complete rewrite of ASP.NET (goal>>cross platform, open source)
- 4. Dependency injection system
- 1. Open Source
- 2. Cross Platform
- 3. Easy integration with client-side libraries some of these libraries like react, angular, vue.js
- 4. Lightweight and high performance
- 5. Cloud-ready
- 6. Apis on par with the .NET Framework
Asp.Net Full Framework App
Visual Studio Dependency
Web.Config & XML
No dependency injection by default
Tied to configuration
ASP.Net Core App
WWW Root folder
No System. Web Dependency
JSON, INI & XML (project.xml)
Built-in dependency injection
Decoupled From Configuration
- variable is a name given to a storage location in memory, where we can store a value
int Number = 1;
Constant: an immutable value that is a value we cannot change dynamically.
- Constant is used for safety in our application that involves some mathematical calculations.
const float Pi = 3.14f;
- cannot start with a number
- cannot include whitespace, it has to be one word.
- Cannot be a reserved keyword
Use meaningful names:
1)camel case: firstName
2)Pascal Case: FirstName
3)Hungarian notation”strFirstName ->not use in c#
For local variables: camel case: int number;
For Constant: Pascal case: const int MaxZoom = 5;
byte number = 255;
number = number + 1; output -> //0
MVC Architecture separates the three main components
MVC (Model - View - Controller)
Model:- Application Data and behavior in terms of its problem domain and independent of the UI. The model represents the data and does nothing else. The model is independent of the controller or view.
View:- The HTML markup that we display to the user. The view is the component that displays the application’s user interface (UI). Typically this UI is created from the model data.
Controller:- Controllers are the components that handle user interaction (HTTPRequest). The controller works with the model and ultimately selects a view that displays UI Responsible for handling an HTTP request.
MVC architectural pattern
Model -> View -> Controller -> Router
Router:- Select the right controller to handle the request.
Url Pattern In MVC
The URL pattern only considered only after the domain name part in the URL