Skip to main content


Fluent mapping approach for EF Core

With the first release of EF Core, there wasn't any proper approach of fluent mapping of entities, in an easy manner for enterprises application where a lot of entities needs to be involved. You might have ended up with nasty or repeated codes.

At that time only way was to compose mapping based on ModelBuilder and by using inline fluent mapping codes. Like in newer version EF Core 2.0 there had been a new release of IEntityTypeConfiguration for the creation of mapping based on single entity and could be registered with ApplyConfiguration by passing a new instance of IEntityTypeConfiguration object. (Self-contained type configuration for code first)
This is really good for big application as we can separate mappings based on each entity.

In this article, we would see how to achieve similar functionality in EF Core 1.0 and this implementation is a bit cleaner than 2.0 built-in classes. So, in both of versions, this could be used w…
Recent posts

jQuery Datatable generic implementation on .Net/dotnet Core for any entity server filtering or sorting through EF/EF Core

jQuery Datatable is one of the popular freely available grid for the developers. It works really great on the client side but there is always need to write a lot of codes on the server side for filtering and sorting for each individual entities.

In this article, we would address this by creating a generic implementation of server code which can work on any entity without writing any further piece of code for filtering and sorting. Just by calling a generic extension method it would resolve sorting and filtering.

The key points to achieve it are as follows:
- Model binding and provider to transform client side request to strongly typed item on the server.
- Once we get strongly typed items to read values, we can apply a dynamic approach to generate queries and filters through LINQ expression.
- At final part, just consumption of created mechanism by creating endpoints for each entity. Also, we can easily select required columns through LINQ projection.
Model Binding As per DataTable ser…

Efficient custom mapping from data model to ViewModel/Dto or vice versa with LINQ support

How many lines of codes we waste on mapping from one source to a destination like DataModel to ViewModel.  There are well-known Mappers available to do the same but nothing can come close in terms of performance by using manual mapping just that we need to write at too many places or takes a huge chunk of code lines in our main codes, may be under controllers, services or where ever you prefer projection in code.

The idea is to develop a proper way to deal with mappings. Some time back I had written code for manual mapping under LINQ queries. Manual model mapping - LINQ projection technique, this still works great. The idea is to create a cleaner solution as a whole new package for handling Mapping which can support general mappings between models and support of LINQ projection to select the limited number of rows as required.

Primary objectives of the implementation.
- A Data model to view model/DTO/or any other.
- view model/DTO/or any other to a data model.
- Support of LINQ proje…

Strongly typed Application configuration through EF SQL DB

The idea is to create a strongly typed application configuration by constructing concrete class and get the values populated from the database so that it is easier to change. This would allow admin to directly modify DB values for configuration.
So, let's start with what we need.
Application setting classes as needed
Classes for application setting. It is just a POCO implementation.
/// <summary> /// Entire application settings /// </summary> public class Setting { /// <summary> /// Gets or sets the setting version. /// </summary> /// <value> /// The setting version. /// </value> public int SettingVersion { get; set; } /// <summary> /// Gets or sets the name of the application. /// </summary> /// <value> /// The name of the application. /// </value> public string ApplicationName { get; set; } /// …

Elegantly dealing with TimeZones in MVC Core / WebApi

In any new application handling TimeZone/DateTime is mostly least priority and generally, if someone is concerned then it would be handled by using DateTime.UtcNow on codes while creating current dates and converting incoming Date to UTC to save on servers.
Basically, the process is followed by saving DateTime to UTC format in a database and keep converting data to native format based on user region or single region in the application's presentation layer.
The above is tedious work and have to be followed religiously. If any developer misses out the manual conversion, then that area of code/view would not work.
With newer frameworks, there are flexible ways to deal/intercept incoming or outgoing calls to simplify conversion of TimeZones.
These are steps/process to achieve it. 1. Central code for storing user's state about TimeZone. Also, central code for conversion logic based on TimeZones. 2. Dependency injection for the above class to be able to use globally. 3. Creating Mo…

Gracefully notifying end user about application error in .Net and .Net Core versions

We generally do error logging for the application to know what error might have occurred in the application. Notifying the end user about the error is equally important. Also, it is always better to implement this at first place rather than doing at a later stage. I have seen many big company's websites ending with .NET yellow page of death. Now, it is really good that the default behavior is removed from .Net Core framework with some generic error message.

We would look how to implement generically and use in older frameworks and some tips on .Net Core as well.

The idea is to create MVC Controller for error and then redirect it from any locations like Filters or Global Exception handling. Also, we would briefly look into the global AJAX error handling system since heavy usage of AJAX in current development trend.

The few steps that we are going to do.
- Represent application errors with enum as system/application have different ways to deal with errors like though Exception or s…