There are a lot of articles telling us how a good REST API should behave. Usually they go with samples. …
I live in Kyiv, Ukraine. Historically we have 2 popular languages here: Ukrainian and Russian. So, any website or web application I create must have at least 2 language versions, single language doesn’t work at all. That’s why I spent some time to make it simpler to develop such websites and web applications.
While there are so many articles describing how to have localized UI in your ASP.NET …
It is a quite usual case when you have a set of the child items of some parent one (order positions for instance) and need to update this set constantly. And “update” means insert, update, and delete at once. Of course, you can manually check which items already exist in the database and update them, which ones should be either created or deleted, but it needs a lot of SQL code and doesn’t look pretty. And it produces ineffective and slow queries.
If you are using a full-featured ORM (like Entity Framework) you can just rely on it and ignore this problem, because obviously it is somehow done automatically. But if you need to use a lightweight ORM (Dapper or so), and if you are using Microsoft SQL Server, let’s look at the better solution. …
Currently I’m working on the new project (basically, this is one of the reasons I write so few articles now). It is food delivery automation system (I own the pizza delivery company located in Kyiv, my hometown; some kind of hobby). It contains the point of sale applications, one of them is web-based. And, as any other POS application, it must print receipts using a thermal POS printer.
As you may know, while it is still possible to print a web page content using any kind of printer (and you basically can get perfect results if you need just to print an A4 document and if you know how to write correct CSS), printing something using a POS printer can turn into a real nightmare. It is rather difficult even when you have direct access to a printer, but you don’t have such access directly from a web page, so that might be tricky. You can’t get rid of browser’s print dialog (there are some workarounds, but still), you can’t send raw commands to a printer, can’t use cutter when you need it, you even can’t control margins and sizes in a normal way. …
Hi! Let’s discuss why it is (or might be) still a good idea to use the Unit of Work and Repository patterns with the Entity Framework Core, while it already implements these patterns itself.
I heard from the different developers many times that it was a bad idea to have the custom UoW and Repository implementations on top of the EF, because they are useless and redundant since EF itself implements them. Yes, it is correct, EF does implement these patterns. But let’s look at the small example in context of the team work:
This code looks nice and returns adult cats sorted by name. But what if you need to get these cats in the different places of your application? You will have to copy it again and again. What if (sometimes in the future) conditions of the adult cats selection will be changed (for example, eight-years-old cats will be considered as adults too)? You will have to find all the places where this code is used and change it (and the standard Find/Replace tools are almost useless in this case because you can’t search by method name or something like this). Of course, you can miss something, and you will have 2 different algorithms for the same logic. Or, for example, you work in a small team, you are responsible for the statistics part, and now you have to display a list of the adult cats. To fix this task you have to look at the database structure, to understand which properties and conditions should be used etc. I think in real life you will have to contact data layer developer and ask him for advice. Again, in a small team it is not so big deal. But assume that we talk about some real-life statistics report generation with multiple joins, includes etc. How can you know how to build optimal query if you have no idea about database structure, indexes etc. …
This time we will see how to setup the MVC routing system to get culture as the URL segment.
ASP.NET Core supports specifying culture using the URL parameter from the box, but the URL in this case should look like this:
In most cases you want to have something following instead:
One way to do it is to inherit the
This code checks whether the culture segment is present inside the URL. If it is not, the default culture is used. If the culture segment exists, it is checked again among the supported cultures.
Then we have to tell our web application to use request localization middleware with our culture provider class as an…
Today we have a very interesting topic to discuss. We will discover and test how different decisions, solutions, and approaches affect the ASP.NET Core web applications performance. We will talk about small and simple things that sometimes are forgotten (and will measure their impact). A huge amount of computing resources is wasted again and again due to unnecessary operations and suboptimal algorithms, and our web applications work much slower than they could. Let’s see what we can do.
I’ve created a sample web application (using SQLite database and Entity Framework Core; you can find it on GitHub), it is something like a simple e-commerce website’s homepage. It displays a category list (as a menu) and 20 articles. Each article is displayed with its category name and photo. So, our database contains 3 tables:
Photos (each article may have several photos, but we display the one with a special flag…
Today we are going to create a simple website you can use as your personal one using the Platformus CMS (it is based on ASP.NET Core and ExtCore framework). You even don’t have to be a developer, we will not write any code for now. The resulting website (that can run on the different platforms, even without standalone web server) will look like this:
Please, follow this tutorial to get and run Platformus.
Time after time, using Entity Framework Core, we might need to execute raw SQL query to count something in our database (or to use other aggregation function). And while using raw SQL queries to select entities is simple, executing aggregation function is a bit more complicated and needs some “low level” classes, like
DbDataReader (class names are a bit different for the different databases, these ones are for the SQL Server).
I wrote small C# extension method for the Entity Framework’s
DbContext class to solve this task:
Now you can easily use it like this:
Feel free to use this code and to ask any questions!
In some reason you might want to avoid using the standard Identity package to work with users, roles, permissions etc. I had 2 reasons:
IUserStoreinterface), but in my project (content management system) I didn’t want to limit future users in this way;
That’s why I decided to write my own. …