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.

Transient, Interface, Abstract

In this lesson, we will have a look at transient, Interface and abstract type implementation using M#.

Transient

Transient by definition is something short-lived or in other words is limited to certain tasks. In M#, transient entities have same meaning in terms of data. M# allows developers to create transient entities, which do not have any mapping to the database. M# does not create a SQL table for the entity marked as transient, but marks such transient entities with [TransientEntity] attribute.

Transient entities usually are used to process some intermediary data or to perform any required business logic which needs to be encapsulated in separate business object /entity.

Creating Transient Entity

Add a new entity "Payment" having selected "Transient" as "Database mode" using M#’s model management as shown below. (For more info: please read lesson 3 Entity, Page, Module in chapter 1)

M# creates an entity class in C# but no database table is created at this time, as shown in below picture:

Interfaces

Interfaces in any programing language accumulate definitions of core related functionalities that a class or structure can implement. This is very important feature especially in .Net programing languages like C# where multiple inheritance is not allowed. For Stuct type, it is even more essential, because a struct cannot inherit from another Struct type.

Creating interfaces

M# allows developers to create Interface types, which can be later be used in Logic partial class of any entity. (For more information on partial classes in M#, please read: Lesson 6 Partial Classes and Business Logic in chapter 2).

You can create interfaces using the same process as mentioned above while creating a Transient entity. You only need to select "Is Interface" checkbox, as shown below:

Abstracts

Abstraction is about encapsulating core concepts but leaving out the concreteness and implementation for specific scenarios, which could be extended later. In Object-Oriented Programing an abstract class contains the core functionalities (definitions or general implementation) for any business logic, which is then inherited and extended as required by derived classes because abstract classes cannot be instantiated and must be inherited in order to consume those core functionalities.

As a developer you can mark any class "Abstract" as required by your business logic. M# allows developers to make any type of entity as Abstract e.g. Transient, Managed etc.

In our tutorial, a good contender for abstraction could be the "User" entity. User contains few properties, which are inherited by "Employee" and will be validated to login and perform actions on our website. So, User entity has no specific or direct interaction with the system, meaning we can mark it as an "Abstract" class. Please follow the steps below to mark an entity as Abstract.

Marking Entity as an Abstract

Select “User” entity in M# Model Management Section.

Click the opposite to the entity name and select “Is Abstract” option in the context menu.

Note: You can also type to filter option shown in context menu, as shown below:

Select the option “true” and build the model, as depicted below

M# marks the User entity as Abstract in generated code