More about Entity Framework

I started getting more familiar with EF Core, although I don’t fully understand everything, I am able to grasp the main idea of how EF Core works, because I helped a friend who is doing his internship as well and was asked to use EF Core and had no idea how to use it. So, I was able to guide here and there which shows that I did learn something about EF Core after all.

If you find difficulties in understanding what I’m about to discuss refer to my previous blog by clicking on this link before proceeding https://www.tonghin.com.my/blog/2021/03/04/entity-framework-core-week/.

I finally have a better understanding of how tests work, and how to write a unit test in general.

A unit test compromises of 3 sections. Firstly, the arrange part which sets the environment for the test components. Next, act initiates the test or does the testing. Lastly, assert validates and verifies the result we expect to get by comparing our expected value to the value retrieved from the act section.

Last week, I wrote around 7 tests with the help of my supervisor, who guides me when I don’t understand or get stuck at one point or another.

Among the widely used assert extensions are First( ), Select( ) and Where( ). More information can be read from the below link https://www.tutorialsteacher.com/linq/what-is-linq.

The concept of Rollback( ), Commit( ) and Complete( ) in a transaction is among the things that I have been exposed to as well, whereby rollback undoes changes that have been committed into the database. Commit on the other hand, saves changes into the database, while complete saves the transaction, it does not update the database if commit was not initiated, as well as if complete was not written in the codes, updates that have been made wont be saved even during debugging of codes.

The keyword using in C# is used to ensure that the method dispose( ) is called after a method has been called, or or an object has been created and many other things. Dispose( ) is used to release unmanaged resources, but it does not free a managed memory.

That’s all for this week 🙂

Variables Value Change According to “Ready To Pick”

In my implementation, Ready To Pick works as a signaling mechanism to let other module know when they could access the sub data in current module. As I working with Ready To Pick function previously, there is new implementation to add on upon clicks on Ready To Pick button.

First of all, in order to press “Ready To Pick” or “Undo Ready To Pick”, we will select a data/item set for example. In this item set, there is multiple list of item will it’s own attributes. Given availableItem and standbyItem as item’s attributes, new implementation is to alter value of attributes by incrementing or decrementing the value upon status of isReadyToPick (bool). Implementation must alter all the value for each item available in item set adding/subtracting itemQuantity.

i) Clicking “Ready To Pick” button when isReadyToPick = false, would change it to true and alter attributes value such as below:
foreach (item in itemSet)
{
item.availableItem -= item.itemQuantity;
item.standbyItem += item.itemQuantity;
}


ii) Clicking “Ready To Pick” button when isReadyToPick = true, would change it to false and alter attributes value such as below:
foreach (item in itemSet)
{
item.availableItem += item.itemQuantity;
item.standbyItem -= item.itemQuantity;
}

To avoid infinite increment or decrement, implementation is done in a transaction, to make sure the logic rollback if there is error. By using transaction, all value changes for isReadyToPick(bool), availableItem(int), standbyItem(int), itemQuantity(int) will be reverted upon any update failure.

Few tests is done to assert value change of availableItem(int), standbyItem (int). Tests assertion pass after “Ready To Pick” button is triggered, the value of attributes add or subtract value of itemQuantity.

After the implementation done, I shall continue implementation logic for situation when item.availableItem -= item.itemQuantity appears to be negative value.

Mostly Database!

Last week, What have I done?

Oh yes, I was still doing the invoices module, fixed the issues related to the services and repositories files as well as created tests for the needed methods in the module. All the created tests have passed successfully.

I have also got exposed to new terms this week. Database transaction which means a unit of work carried out in a database management system. Next, a two phase commit as defined by techopedia.com is “a standardized protocol that ensures that a database commit is implementing in the situation where a commit operation must be broken into two separate parts”. Last concept, Concurrency in database that is known as the ability to control data being saved into the database during a concurrent execution, as in two users saving information on the database at the same time.

Concurrency has two types called optimistic and pessimistic. Optimistic concurrency involves the logic of users being informed when a change is being made to a data in the database, and whether they wish to continue with the changes being made, or in the case of different parts of data being changed, both changes gets updated into the database. Pessimistic concurrency revolves around the idea of initiating a lock or a read-only feature, that is activated when one user is making a change such that other users cannot make a change at the same time. Entity Framework implements the logic of Optimistic concurrency.

Aside from new terms and concepts, I was introduced to data migration from visual studio to database. The entities defined in visual studio were created into the database by using the concept of data migration using Package Manager Console in visual studio.

Finally, I started designing the invoice detail view and binding the commands to the correct view model context.

See you all next week again 😀