.NET, C# and ASP.NET Core tutorials, code examples, courses, videos and coding challenges for software developers to learn.
Focusing on tutorials from frameworks such as Web API, MVC and Blazor, as well as topics ranging from authorisation, dependency injection and configuration to name a few.
We'll also demonstrate some of the new features that are available when a new version of .NET and C# is released.
As a bonus, a number of our tutorials will have code examples so you can download the code from the tutorial and try it out for yourself.
Round The Code
Using Entity Framework Core but not sure how to store a DateTime?
If you rely on converting a DateTime to a different timezone, one of the best ways is to store the DateTime as UTC in the database. That way, you can decide which timezone to display the DateTime in your application as you know you will always be converting it from UTC.
And there is an easy way to do this in EF Core. You can create a ValueConverter that allows you to transform a value when saving it to the database and replicate that when getting the value from the database to the application.
And the great thing about ValueConverter's is that it's possible to apply it in a DbContext to all properties of a particular type.
Watch my video where I create a DateTimeUtcConverter class that saves the time as UTC in the database, and then converts it back to the local timezone in the application.
1 week ago | [YT] | 6
View 0 replies
Round The Code
If you are using Entity Framework Core and want to know an easy way to store dates and times, watch my latest video where we show you an easy way to store dates as UTC in the database and then convert them back to your local time zone.
This is essential if your application spans across multiple time zones.
2 weeks ago | [YT] | 12
View 0 replies
Round The Code
Static web asset file sizes can be reduced by over 80% thanks to a new .NET 9 feature.
This is great for users on a slower network like a mobile as it reduces the overall response time.
Watch my video to find out how it works and how you can enable it.
4 months ago | [YT] | 6
View 0 replies
Round The Code
C# 13 was launched as part of the .NET 9 release last week.
C# 13 has a number of new features and this video will go through each of them and show you how to use them. It will also show you how you can start using C# 13 today, and how you can use it even if you're not updating your application to .NET 9.
5 months ago | [YT] | 8
View 0 replies
Round The Code
.NET 9 has been released!
Find out how you can update your ASP.NET Core application to .NET 9.
We also look at the breaking changes to see what things might break your application.
And finally we ask whether you should update to .NET 9, or stick with your current .NET version.
5 months ago | [YT] | 4
View 0 replies
Round The Code
There are many helpful features in EF Core with migrations that you might not know about.
𝗘𝗻𝘁𝗶𝘁𝘆 𝘁𝘆𝗽𝗲 𝗰𝗼𝗻𝗳𝗶𝗴𝘂𝗿𝗮𝘁𝗶𝗼𝗻
You can override the OnModelCreating method in your DbContext to configure your entities.
But did you know that you can also create your own class for each entity configuration?
You'll need to implement the IEntityTypeConfiguration interface in the class passing in the entity as the generic type, and implement the Configure method to configure your entity.
To use it in your DbContext, you'll need to override the OnModelCreating method and call ApplyConfigurationsFromAssembly method from the ModelBuilder instance, loading the assembly where your entity configurations are stored.
𝗦𝗲𝗲𝗱 𝗱𝗮𝘁𝗮
This allows you to populate a database table with an initial set of data that is used across all environments.
You can call the HasData method inside the EntityTypeBuilder type when configuring an entity, and add the data you wish to be populated to the database.
𝗩𝗮𝗹𝘂𝗲 𝗰𝗼𝗻𝘃𝗲𝗿𝘁𝗲𝗿𝘀
This allows you to convert your data into a certain format when saved to the database. Then you convert it back when it's used in the application.
An example of this is saving a date and time in the database using the UTC timezone. You can then convert it back to the local timezone on the server when used in the application.
You can do this by creating a class and inheriting the ValueConverter type.
𝗥𝘂𝗻𝗻𝗶𝗻𝗴 𝗮 𝗦𝗤𝗟 𝗰𝗼𝗺𝗺𝗮𝗻𝗱
You can create an empty migration script in EF Core and in the MigrationBuilder type, you can call the Sql command to run a query when performing this migration.
An example of this is if you want to create a new column in a database table and populate it with an initial set of data based on the current record.
𝗪𝗮𝘁𝗰𝗵 𝗺𝘆 𝘃𝗶𝗱𝗲𝗼 𝘁𝗼 𝗳𝗶𝗻𝗱 𝗼𝘂𝘁 𝗺𝗼𝗿𝗲 𝗮𝗯𝗼𝘂𝘁 𝘁𝗵𝗲𝘀𝗲 𝗶𝗻𝘃𝗮𝗹𝘂𝗮𝗯𝗹𝗲 𝗳𝗲𝗮𝘁𝘂𝗿𝗲𝘀.
8 months ago | [YT] | 2
View 0 replies
Round The Code
You can use the HttpClient class to send HTTP requests in an ASP.NET Core application.
However, there are a few ways you can initialise this and some ways may cause you problems.
One of the ways you can do it is to initialising a new HttpClient class with every request. However, the problem with this is that the HttpClient class is only meant to be initialised once per application.
This is because each HttpClient instance uses its own connection pool which involves using an available TCP port on the server.
When the HttpClient instance is disposed, it will dispose the connection pool, but doesn't release the TCP port immediately.
As a result, if you make too many of these requests in a short period of time, it'll mean that there will not be enough available ports to make a connection and you'll start to have socket exceptions when making API requests.
The best way for you to do this is to use IHttpClientFactory which helps with HttpClient instance management.
Watch my video to find out how to use this.
8 months ago (edited) | [YT] | 4
View 0 replies
Round The Code
If you want to toggle features on and off in ASP.NET Core, you can use the feature management tool.
By adding the Microsoft.FeatureManagement.AspNetCore NuGet package to your application, you can enable or disable certain features in your application. You can even show a certain feature to a particular user.
You can use appsettings.json to configure which features are displayed and it can be used in MVC and Web API using the FeatureGate attribute.
Watch my video to learn how you can add feature flags to your ASP.NET Core application.
8 months ago (edited) | [YT] | 1
View 0 replies
Round The Code
Have you tried using VS Code to develop a .NET application?
Watch my video where we develop an Web API project and run it using Visual Studio Code.
Learn how to install the C# extension and use the terminal to create classes, interfaces and API controllers.
There is also a demo on how you can debug an application in VS Code.
How does it compare to Visual Studio?
10 months ago | [YT] | 5
View 2 replies
Round The Code
The try, catch and finally code blocks don't always fully run in C#.
Watch my video to find out the different scenarios as to when they run, and what the difference is between ASP.NET Core applications and console applications.
10 months ago | [YT] | 4
View 2 replies
Load more