EF Core Performance

Last week , I worked on optimizing the runtime of loading inventory items . The problem is a “Cartesian Explosion” that is related to performing joins . When we perform a join , one’s table repeat the X number of time the matched records of another joined table . There are a few ways to avoid the cartesian explosion especially when loading related entities in a huge database :-

  1. AsSplitQuery() introduced by EF core 5.0 . It only works when using Include(). Instead of joining the tables , split queries generate additional SQL query instead of single queries .
  2. IncludeOptimized() introduced by EF core pro . It works similarly to the first method as it drastically decreases the amount of data transferred to avoid generating excessive data that is needed .
  3. Explicitly loading the data needed in the single query .

In conclusion , unfortunately there isn’t one solid solution for loading all entities that fit every scenario . IncludeOptimized() does not support AsNoTracking() and cannot be mixed with Include() . In hindsight , explicit loading should be the way to fix the cartesian explosion problem as there are limitations to using built in functions .

Implementing wrappers

Last , I was given a few issues in my git repository. Previously in the SandBox application , data were selected in the ComboBox with SelectedValue , showing names with DisplayMemberPath . I was advised to use wrappers instead for more maintainable code . After implementing the wrapper instead of SelectedValue and DisplayMemberPath the codebase became less complex .

A Wrapper class “wraps” an object of another class. It is used to implement a design pattern that has an instance of an object and presents its own interface to that object, without changing the original class .

I also fixed some bugs in the ViewModel and integration tests between modules . In the ViewModel , methods were called twice causing errors, because EventAggregator was subscribed more than once, once in a method and another in the constructor , to fix this I removed the subscription from the constructor , fixing the bug while making the integration tests pass.

That is it for last week . For next week , I will be planning a model for stock threshold in the application .

UI Navigation Tabs

Last week , I have been given tasks to create navigation tabs using INavigationAware in the SandBox App . There are a few things implemented once I applied the INavigationAware interface into the view model .

First , IsNavigationTarget is a bool method method that allows an existing view or view model to indicate whether it is able to handle the navigation request .

Then , OnNavigatedFrom method is to allow the previous view to save or deactivate any current events from EventAggregator. The OnNavigatedTo method is called when the view is initialized , to pass on data from the navigation parameters .

Also , the NavigationContext that prism provides is to receive parameters from the NavigationParameters class , that is passed from the RequestNavigate method .

Prism also provides the IRegionMemberLifetime interface that has a KeepAlive boolean , to control the views to set them whether to be deactivated or not .

Lastly , after the implementation of navigation activities . I created some tests for services in the project , restricting the deletion of table if foreign key exists .

Domain Driven Design

For the past week , I have been working on creating repository patterns in the project .

Throughout my coding experience in the Tong Hin Sandbox Application . I have implemented some of the common DDD patterns in the project .

In DDD , the Domain normally refers to the “pillar and activity around which the application logic revolves around” . The DDD pattern aims to ease the complexity in an application .

Common terms used in DDD practices :
– Ubiquitous Language: A language structured in the project between team members to solve conflicts
– Bounded context: A description of a boundary within a model
that is defined and applicable to team members
– Aggregate : An aggregate is an encapsulation of entities and value objects
– Service : A functionality that must exist but cannot relate to an entity or value object
– Repository : An interface to allow CRUD around a project

With these practices , it helps to minimize the complexity of the code . These are just the common terms used and there is more to know as I complete new tasks.

Testing phase

The past week , I did concurrency tests , automatically creating item names with concatenating strings , set bindings and some UI updating .

UI updates were setting auto-generated item names to read-only so user cannot edit textboxes , adding new textboxes with new property. Also, adding migration to the database with the latest updated property .

String concatenating (meaning linking a string in a chain or series) is to join different property of strings together , while implementing the logic in Wrappers to save different strings concatenated into database.

The concurrency problem I faced was when two users execute a transaction simultaneously . Ideally in this situation, the first user transaction will succeed and the second will fail .The common concurrency problems that potentially happen in DBMS transactions are usually :

  1. Temporary Update Problem
  2. Incorrect Summary Problem
  3. Lost Update Problem
  4. Unrepeatable Read Problem
  5. Phantom Read Problem

https://www.geeksforgeeks.org/concurrency-problems-in-dbms-transactions/

However , one way to fix a concurrency problem is when the second user fails transaction , is to reload its transaction entry . Then resave it by clicking the save button again .