M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

The role of IsNew

When you have to perform an operation on an instance in some cases you need to know whether it is a new or an existing instance.
To do so, M# provides you the readonly boolean property IsNew.


In the image above you send an email to the employee depending on if he is a new employee or not. We can imagine other scenarios in which IsNew could be used, for example in the case when the initial password of a newly created employee is auto-generated by the system.

Equals()

The Equals function will return true if the two instances are the same, have the same Type and ID.

Clone() vs EntityManager.CloneAsNew

You have two different ways for cloning an instance: Clone() or EntityManager.CloneAsNew().
Clone() returns a new Employee object with the same ID of this instance and identical property values. The difference with the original instance is that this instance will be unlocked and thus can be used for updating the database.
EntityManager.CloneAsNew() returns a clone of the instance, but the difference from Clone() is that the clone is marked as new (IsNew = True) and it has a new ID.

To summarize, Clone() is used to update an object and EntityManager.CloneAsNew() for duplication.