Enumeration Mapping – Introduction

In many cases, you may have tables for value lists in your database that only hold an integer primary key and a description field. Then when you want to display this description, you’ll have to join the table every time. It is not a problem for dynamic value lists or if they change on a regular basis without the need for new code implementation. But if they are static, the join looks more like a waste of time. One of the most common example is the order state in sales applications. There are only a few values like New, In Progress, Delivered and each value requires some specific code implementation. You could of course decide to load those static data when your application starts and cache them. But Entity Framework has another solution to that issue: enumeration mapping. This allows you to convert any integer field of your model to an enumeration type. This feature has some interesting advantages:

  • You no longer have to join the value list tables every time you want to get the description;
  • You don’t have to implement a caching system for value lists;
  • Enumeration types are much easier to use in code than pure integer values.

Application logging configuration

The following steps will guide you through the configuration process of your application to enable default logging support.

First of all, open the KeepItSoft.Fwk.Utility.ttinclude file which is attached as a solution item. In the constructor of the ProjectConfigurator class, set the value of the UserLogger property to true. This property is used by some of the T4 generators to provide a default logging behavior when a critical exception is raised in the business logic layer. Save the file and run the T4 transform tool to generate this behavior.

All you have to do now is check your configuration files so that all binding configurations correctly target your deployed log service. The Service.ConsoleHost and UI.WPF.Views projects already define client bindings for both the ILogService and the IApplicationManagerService contracts. Update those to match the service you deployed. Be aware that if you deployed the LogManager template, you shall also adapt the namespace of the endpoint’s contract to target LogManager rather than ApplicationManager.

As mentioned earlier, the logging system’s automation process is based on the application id. So before going any further, be sure that your configuration files declare an application setting called ApplicationId whose value corresponds to the id of your application as saved in Log Manager/Application Manager.

Extending generated managers

All generated managers (one for each entity type) inherit the same base class whose name is the concatenation of the value configured in the BaseClassPrefix property (which is a member of the ProjectConfigurator class located in the KeepItSoft.Fwk.Utility.ttinclude solution item) and ManagerBase. In order to add a method to a manager, please follow the following steps :

  • Under the Partial folder of the Business.Logic project, create a partial class for the manager you want to extend;
  • Implement your method in this class.

Paging in collection views

Whenever a collection view shall hold too many items, you can enable paging in order to reduce loading time and network consumption. For this purpose, please follow the following steps:

  • In the constructor of the collection view, before the call to InitializeComponent, set the IsPagingEnabled property to true.
  • Add a DataPager control (KeepItSoft.Fwk.WPF.Controls) to the collection view and bind its PagerContext property to the Pager property of the collection view (Figure 1).
pager-xaml

Figure 1

In order to make this feature work, the Count delegate is required so don’t forget to pass it when you call the Initialize method of the base class.

Please be aware that the above steps only allow you to enable paging with sort and filter expressions that are declared by code. By default the datagrid only applies filters on data that it holds in its context. I’ll explain in another post how to allow dynamic sort and filter expressions with paging.