2020

Entity Framework Core - preview model

In this article, I show you VisualStudio extension EFCorePowerTools written by Erik Ejlskov Jensen which lets you see how Entity Framework Core interpreting your model. This extension is very helpful to avoid problems when EF Core interprets the model in a different way than you anticipated. EF Core has some conventions that you should follow to receive the desired database schema. With this extension, you don’t have to apply the migration to the database to see if you didn’t make any mistakes in your model. You can preview the model in the graph or you can generate SQL scripts to see what will be generated in your database.

1 min read

WPF - create custom button with image (ImageButton)

In this blog post, I will show you how you can create a custom control ImageButton. In this control, we will use Grid control to locate our image and the content of the button will be always in the center of it. You don’t have to specify the button content - in this case it will be an image button only. ImageButton inherits from Button so you can access all button’s properties. Additionally, you can set the following properties:

  • ImageSource
  • ImageLocation (Left, Top, Right, Bottom, Center)
  • ImageWidth
  • ImageHeight
2 min read

ASP.NET Core Tag Helpers - Cache Busting

Have you ever had a problem with stale JavaScript or CSS files in browsers using by your customers? How many times did you explain to your customers that they should clear the cache? And how many times did you hear the following words “How do I do that?”? If you don’t want to have these problems in the future please read this blog post.

1 min read
Back to Top ↑

2019

Secure static files in ASP.NET Core

The Static File Middleware doesn’t provide authorization, all files served by this middleware are publicly accessible. Static files are stored in the following directories:

  • Web root directory - {content root}/wwwroot - it’s the default directory
  • you can also serve files outside the Web root directory by specifying it in the UseStaticFiles method as below:
~1 min read

Entity Framework 6 - optimistic concurrency

Concurrency conflicts occur when more than one user wants to edit the same entity stored in the database at the same time. Let’s say that we have two users Mark and John currently using our application and they want to edit the same entity stored in DB which Id is equal to 2 (please refer to image below).

2 min read

C# 6 feature - using static directive

In C# 6 was introduced using static directive. By using this language construct you can reference to static class members without specifying a type name.

2 min read

WPF Validation - Using INotifyDataErrorInfo

In the .NET 4.5 was introduced new interface INotifyDataErrorInfo which enables data entity classes to implement custom validation rules and expose validation results asynchronously. This interface has three members:

  • HasErrors property indicates whether there are any validation errors
  • GetErrors method returns an IEnumerable that contains validation errors for the specified property (when the propertyName parameter isn’t equal to null or empty string) or for the entire entity (when the propertyName parameter is equal to null or empty string)
  • ErrorsChanged event must occur when the validation errors have changed for a property or for the entity
2 min read

WPF Validation - Using IDataErrorInfo

In this blog post, I will show you how you can validate data using IDataErrorInfo. This interface has only two members which need to be implemented:

  • public string Error { get; } - gets an error message indicating what is wrong with this object
  • public string this[string columnName] { get; } - get the error message for the property with the given name.
1 min read

Entity Framework 6 - speed up reading the data

If you want to read data from the database without need of editing it later you can improve your query by using the AsNoTracking method. This “read-only query” is quicker to execute because EF will no need to set up change tracking information about every single loaded entity.

1 min read

WPF Validation - Display errors to the user

In this post, I will show how you can present user input validation errors to the user. By default, WPF shows a red border around the TextBox when the entered value is invalid. But in this case, our user has no idea what is wrong with entered data. We need to inform the user by providing an error message on the view.

3 min read

WPF Validation - Using ValidatesOnExceptions

In WPF we have few options to validate user input data. In this article, I will show you validation based on the exception. This validation is applied in very simple solutions. The only thing you should do is throw an exception on property level and set ValidatesOnExceptions to true in the view.

1 min read

Json.NET - ignoring properties during serialization

When you’re using Json.NET to serialize an object by default all public fields and properties will be serialized. In this case, if you want to ignore some of them you can use JsonIgnore attribute. In the following example, you can see how you can ignore SSN property during the serialization process.

1 min read
Back to Top ↑

2018

Improve built-in ASP.NET Core DI container with Scrutor

ASP.NET Core has built-in dependency injection (DI) container. It’s easy and simple for the smaller project where you register all your dependencies (e.g. services, repositories, e.t.c.) by hand. Microsoft.Extensions.DependencyInjection has not built-in type scanning functionality, so if your project will grow, using it can be pretty hard. But you can resolve this problem by using Scrutor. Scrutor is an extension for built-in DI that allows you scan assembly and decorate services. In this article, we will look at scanning functionality.

1 min read

C# 7: check null properly

If you develop application with C# 7 and you want to be sure that null is always check properly you should use constant pattern “null”. This is one of the 3 types of patterns in the new feature in C# called “pattern matching”. In this case, you don’t have to bother if in the class is defined override of the equals operator. In the following code snippets, we will go through two types of checking null (is and ==) and with or without override == operator.

4 min read

Quickly Launch Apps with Windows Key + R

In Windows operating system the run command window is the fastest way to access almost all Windows’ function. To open the run command window just press Windows Key + R. After that, you can enter a command to the Open textbox and press Enter. Below I gathered the most useful commands which you can use in daily basis work.

~1 min read

DevExpress WPF Themes - how to apply theme to an entire application

DevExpress theme manager has an important property ApplicationThemeName. This property allows you to set global theme applied to the entire application. Without settings this property, you have to specify theme name on every new window in your project.

1 min read

Visual Studio 2013 designer cache & disk space leak

I have recently encountered a problem with using VS2013 designer when I develop WPF application. Problem is with a designer cache which is not cleared out. After about three months I have ended up with 0 bytes on my C drive and I was not able to do anything. When I started searching for the possible cause of this situation I found information about the bug in VS2013 connected with the correctly delete cache data from disk. In my case, about 30GB of storage was being used by VS2013 designer cache.

1 min read
Back to Top ↑