The Lost Update Problem in Concurrent Transactions

The lost update problem occurs when 2 concurrent transactions try to read and update the same data. Let’s understand this with the help of an example.

Suppose we have a table named “Product” that stores id, name, and ItemsinStock for a product.

It is used as part of an online system that displays the number of items in stock for a particular product and so needs to be updated each time a sale of that product is made.

(more…)

How generics save from boxing

At the method input, we often perform a null test. Someone makes the test as a separate method, so that the code looks cleaner, and gets something like this:

The interesting thing about this test is that I see a frequent use of the object attribute, though you can use generic. Let’s try to replace our method with generic and compare performance.

(more…)

GitHub for Windows Users

If your project is stored only on your disk, then you are in for trouble when the disk fails. Even a regular backup will not always save you.

Some developers make so much mess in the project and hardly remember what and where was done.

The version control system will help you avoid these problems. If necessary, you can restore or rollback changes, view, confirm or cancel edits. Well, teamwork without a version control system is simply impossible.

(more…)

Entity Framework: (anti)pattern Repository

A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to Repository for satisfaction.

Entity Framework provides us with the actual implementation of the Repository patterns: DbSet<T> and UnitOfWork: DbContext. I often see colleagues using in projects their own implementation of repositories on top of the ones existing in Entity Framework.

(more…)

Counting references to a record in a table via Foreign Keys

I have recently needed to solve the task for my own purpose: to calculate the number of external records linked by a foreign key for each record in a table (File). The task was solved for the specific structure of the File table, but if necessary, the solution can be reworked to a universal one.

I’ll clarify that the solution was developed for an unloaded database, without millions of records and an every minute update, so there was not much concern about the performance.

(more…)

Modular WPF application using Caliburn.Micro and Castle.Windsor

To start with, I want to specify what is meant by a modular application in this article. So, a modular application will be considered an application, which consists of the so-called shell and a set of plug-in modules. There is no direct dependence between them, only via contracts. This allows independently modify each of the components, change their contents, etc. I think everyone knows the advantages of modular architecture.

(more…)

Synchronizing database structure between applications

Anyone who has ever developed applications that use a database has probably faced the problem of updating the database structure when the application is deployed and updated.

The most common approach is to create a set of SQL scripts to modify the database structure from version to version. Of course, there are paid tools, but they do not always solve the problem of full automation of the update.

(more…)