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 🙂

Entity Framework Core Week

Getting familiar with EF Core is not easy at all.

Last week was hectic, I really had a lot of trouble trying to understand how EF Core works and understanding its concept, to the extent that I told my parents, I guess my supervisor regrets taking me as an intern, hahhahah.

So entity framework can simply be defined as an object which maps database to .NET. Mainly, Entity Framework (EF) and Entity Framework Core exist, such that the latter is an advanced version of EF and it supports features that EF cannot support .

EF Core is what we use at Tong Hin. It works by creating model classes and context objects which represent sessions with the database. Migrations are then used to create the database and update it as the model evolves and changes. EF Core supports relationships in database, ranging from One-to-One relationships, One-to-Many relationships, and Many-to-Many relationships.

EF Core can be used for querying and retrieving data from the database, save, edit and delete data. Taking note that all these functions are done in the model class of the entities.

The concept of EF Core is a lot, I will mention more about it in the next upcoming blogs.

Next, I was introduced to fluent assertion, which makes the assertion statement readable to anyone who has a look at the codes instead of using the statement Assert(2, 4), the following statement is more readable and understandable Answer.Should( ).Equal(2).

Clean code is a concept which involves ensuring that the codes written are easier to understand and are easier to change. Clean code can be written by adhering to the following basic guidelines which are, writing meaningful names, writing correct comments, following the standardized format of code writing, removing and refactoring unnecessary classes, and many other guidelines that can ensure that the codes written are considered as a clean code.

See you all next week again 🙂

Wrappers, DAL and Pub/Sub

Basically, I get to learn new concepts and terms everyday at Tong Hin.

Last week, I got to know what DAL, Pub/Sub and decoupling mean.

I also got exposed to the reason why Wrappers are used instead of ViewModels. The reason is that Wrappers are used to hide the complexity of ViewModels and WrapperServices are used to hide the complexity of Wrappers. Such that programmers get access to the codings they need without having the need to go through the complexity that lies underneath the functions they are using.

Data Access Layer (DAL) is an interface which simplifies and gives access to data stored in persistent storage, it returns a reference to an object instead of returning a row of fields from the database. DAL is used to call methods such as insert, update and delete from methods in the class which would return objects that contain the needed values.

Pub/Sub which is also known as Publish-Subscribe is a software messaging pattern that allows messages to be sent from publishers to users (subscribers) without them getting involved in sending the message to the subscribers. The messages are sent to channels in which these channels are responsible of retrieving the messages from the publishers and sending them to subscribers.

On the other hand, coupling is defined as the level of interdependence among two software modules, thus, decoupling is the opposite, in which it means how unconnected two modules in a software program are found to be. Two software programs or modules are said to be decoupled when a change is done in one module, the other module does not need to be changed or in other words, the other module is not affected by the change that has occurred in the other module.

Lastly, I was taught how to create tests in a better and more efficient way. Instead of using Assert, Fluent Assertion is a better alternative to be used.

That’s basically a summary of what I have been through last week.

Wait for me next week again 🙂

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 😀

Guess What

Heyyyy, it’s me again and this week, I’ve come with new things to share with you all!

Well, I would say that my performance this week was way better than last week. Just imagine, during the first week, when I used to look at the pile of codes and scroll through them, my head spins and I start seeing things in two, hahahahaha, okay I’m exaggerating, but honestly, it was so much to swallow and understand especially with the fact that this is my first time to literally get exposed to these things, everything is brand new to me.

Firstly, I tried to use input binding in resource dictionary but still couldn’t do it, because the problem was raising from the data context, the resource dictionary was not able to get access to the data context of the file which contains the definition of the commands. Then, I tried using the data context concept but still no success. So, I asked my supervisor to move on, yes I did told him that, because I was already losing interest in doing the same thing over and over again. So, I was asked to write a test for the Escape key, well I would say that I only managed to do 50% of the task, I also learnt the difference between Setup and Verify when using Moqs.

Before having a look at the difference between Setup and Verify, a simple definition that can be given to Moqs is that they are objects which mimic or copy the behavior of a class or an interface and allows methods in the test to interact with them as if they were real. Hence, Setups are usually associated with the fact that we set a method and invoke a return that we expect to be returned when the method has been set up or initiated. On the other hand, verify deals with the concept of ensuring that a certain method gets invoked when the requirements are fulfilled, such that we want to verify that when method A is invoked B should be returned, if B is not returned hence our test fails. Unfortunately, the test I wrote was only for checking whether the command gets executed or not, but not whether the escape key was pressed, because the definition of the key was written in the .xaml file not the .cs file.

Next, I was given a new task, in which I had to create a module for invoices which is related to a system being created. I’ve also updated my dictionary of definitions, so initially I had the idea that data context meant giving access to the data in other classes when in reality it means a network connection created among data points in files. I have also learnt that the .sample files extension in projects are not supposed to be deleted but to be kept and used for references.

Lastly, I have also created tests to test the data being saved into the database. Basically, the tests I wrote were to ensure that the data types assigned to each attribute is correct and is the data type required, meaning a test method is written to check whether the attribute name is assigned a string data type, if the name is not assigned to string then the test fails, because the actual and expected data types are not the same.

Basically, that’s a summary of all what I did, see you all again next week. Make sure you read my upcoming blog, which is surely to be filled with new things to learn 🙂

Fresh start!

My first week have just passed at Tong Hin and all what I can say is, it is a new experience for me.

The first week wasn’t easy, I was exposed to many areas I have never encountered before or heard about, but honestly, it is a great experience to explore more and get to learn new things especially with the guidance and help of my supervisor.

I got exposed to Bitbucket, Sourcetree, and Dropbox. I got to know that Bitbucket and Sourcetree are alternatives that can be used instead of GitHub.

Creating stashes was also something I got to learn, in which you can save changes that have been made to the codes and apply them again after some time.

InputBindings is used to bind an input to a command or invoke a command upon input given by the user. The input can be given from the keyboard or mouse gestures. However, the focus should be adjusted in which the application is set to have an area of focus where the command is executed depending on the area where the user gesture is detected.

Delegate Commands are part of the interface ICommand, in which the delegate commands are used to invoke methods that are assigned to commands when the command’s execute and canExecute methods are called.

Next I was introduced to converting ICommands to become delegate commands and using multiple views into another view. In other words, to use methods in a class in another class.

Resource dictionary are XAML files that can be reused across the application without the need of writing the same code over and over again. With resource dictionary, referencing to the XAML will allow the class or the view class to get access to that part of the code. However, I was having trouble using the Inputbindings method into the resource dictionary, because the dictionary is not able to recognize the function.

Basically, for this week I was able to use the Escape key to open dialogues, and the dialogue displayed uses the cancelDialogueView as well as I was able to create a resource dictionary which needs adjustments to be made next week.

Hopefully by next week I would be able to accomplish more and learn more to share it with you guys, see you all on my blog next week 🙂