A free website for beginners to learn the new technologies like Appian, .NET, Java, Low-Code Development etc. Detailed solutions to your bugs and errors in the Applications.
Building distributed applications can be a complex and time-consuming process. Thankfully, .NET Aspire is here to simplify the process and help you build observable, production-ready applications with ease.
.NET Aspire: Simplifying the Cloud-Native Development Journey
.NET Aspire is an opinionated stack within the .NET ecosystem, providing a pre-defined architecture and best practices for building modern applications. It focuses on three key areas:
1. Cloud-Native:
Seamless integration with cloud platforms like Azure
Streamlined deployment and management
Scalability and flexibility
2. Observability:
Rich telemetry data for monitoring and troubleshooting
Built-in logging and tracing
Improved application insights
3. Standardised Interfaces:
Consistent and predictable components
Reduced development complexity
Easier integration and maintenance
Benefits of Using .NET Aspire:
Faster Development: Get started quickly with a pre-defined architecture and standardized components.
Improved Scalability: Build applications that can easily grow and adapt to changing needs.
Enhanced Observability: Gain deeper insights into your application's behavior for better troubleshooting and performance optimization.
Reduced Costs: Streamline development and minimize infrastructure setup, potentially leading to cost savings.
Focus on Business Logic: Dedicate your time and energy to building core functionalities instead of infrastructure concerns.
Who Should Use .NET Aspire?
.NET Aspire is ideal for developers building:
Modern, distributed applications: Microservices architectures, event-driven systems, and reactive programming.
Cloud-based applications: Leveraging the benefits of cloud platforms like Azure.
Highly observable applications: Gaining deeper insights into application behavior and performance.
Maintainable and scalable applications: Building applications that can grow and adapt to changing requirements.
Who Should Use .NET Aspire?
.NET Aspire is ideal for developers who:
Want to build modern, distributed applications efficiently.
Seek the benefits of microservices architectures and cloud platforms.
Focus on building core business logic without infrastructure concerns.
Value improved observability and maintainability in their applications.
Today we will create an asp.net core MVC application using EntityFramework and MySQL Database with Visual Studio 2019 for Mac.
This is a simple CRUD operation for an Employe using ASP.NET Core 3.1 and EntityFrameworkCore
Prerequisites:
Visual Studio 2019 IDE for Mac
Make sure you are running the latest .Net core 3.1
Install the latest DOTNET and EF CLI using this command: dotnet tool install --global dotnet ef
MySQL database should be installed on your Mac
Getting Started:
Open the Visual Studio 2019 for Mac and Create a New Project as below
Please select the .Net Core 3.1 as below
I created a new project with the Name, "DotNetCore" and below is the Solution structure which
is created by VS2019.
Let's install the few mandatory nuget packages as below
1. Microsoft.EntityFrameworkCore
2. Microsoft.EntityFrameworkCore.Design
3. Microsoft.EntityFrameworkCore.Tools
4. MySql.Data
5. MySql.Data.EntityFrameworkCore
Now let's add a New Class name "DotNetCoreDbContext" under the Models folder by right-clicking
and select Add New Class.
Now let's write the code for this class.
We have to inherit our class from the DbContext class by using Microsoft.EntityFrameworkCore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now let's add a New Class name "Employee" under the Models folder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now add our class into DotNetCoreDbContext as below
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now we need to write code for ConnectionStrings in appsettings.json file
and modify the Startup.cs file as below
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Next step to add the Migration to create the Database in MySql
Run below command w.r.t your project folder path on Terminal
To Add-Migration:
dotnet ef migrations add InitialCreate
To Update-Database
dotnet ef database update
To Remove-Migration:
dotnet ef migrations remove
After adding the Migration, we can see our database has been created into the MySql database
We can see our created database dotnetcore including the Employees table.
Now let's add the controller name "EmployeeController" using Scaffolding as below
We will use the same action for Create and Edit an Employee.
Let's write the code for AddOrEdit action into EmployeeController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now let's add the view page for AddOrEdit action under the Views/Employee folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We have written the code to create and edit an employee, added the view page also.
Now let's build our solution and run the application.
Let's create 3-4 employees by entering the required fields as below
Let's write some action methods to Index, Details, and Delete an employee as well
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters