-
Notifications
You must be signed in to change notification settings - Fork 0
Lightweight Entities
Lightweight Entities (LWE) are a feature of SoftFluent CodeModeler which allow developers and architects to model “light” objects. By light we mean objects such as a Point class which contains two coordinates properties X and Y. By defining this object as a LWE, CodeModeler will consider it as a light object that is not persisted, nor has a collection class and all the features and/or methods that standard entities have.
This being said, more than just enabling to model light objects, LWE have advanced features such as the capability to map them to .NET types, to persist them as part of a standard entity to which it's associated, or to be used as a return type of a CodeModeler method. LWE can also be automatically created as projections of a view.
To get back to our Point object example, declaring a LWE named Point and to which no standard entities is linked to, will generate a single class Point in the BOM. This class is not persistent (no corresponding tables in the database will be generated) and doesn't contain all the Create-Read-Update-Delete (CRUD) methods nor the validation or tracing methods neither.
To create a LWE using Visual Studio, just create an entity as usual, add properties and then set its “Is Lightweight” attribute to True.
A LWE will be displayed with a surrounded dotted line in the design surface:
Here, even though the Point entity is a lightweight entity and consequently it isn't persistent; since the Circle entity is persistent, columns Point_X and Point_Y will be added to the Circle table. Nevertheless, in the BOM, the persisted values will be available in a Center property of type Point.
From a .NET point of view, in this case, it would be more relevant to generate a structure (ValueType) rather than class (ReferenceType). To do so, you must set the “Value Type” attribute (“Aspects and Producers Properties” tab) to True:
Furthermore, as said earlier, it's possible to map a LWE to a standard .NET type, such as System.Drawing.Point in our example above. See the Reusing .NET Types chapter for more on this.
LWE do not have persistence methods (load, search, delete, save) since they are not persisted. However, it's possible to define raw methods on LWE such as shown in the example below:
Such methods will be generated in the BOM as static methods.
In conclusion, lightweight entities (LWE), as the name suggests, are light objects. Even though LWE might not represent business concepts, it sometimes can be handy to model those concepts (such as Point, or an Address for instance) in the business model in order to ease further developments. Moreover, just like any other entity, LWE are available in all layers and are serializable so they can be used in “Services” (SOA, Micro Services, Cloud, etc.) environments as well.
An entity can have persistent views, and views can be used in methods.
As we've seen earlier in this article, lightweight entities can be used as method return types to return a set of columns. Consequently, the next logical step would be to be able to map a lightweight entity to a persistent view in order to have an actual object representation of it in the Business Object Model (BOM).
CodeModeler allows developers to do so thanks to the “Auto infer lightweight entity” attribute available as a checkbox on the view editor:
Note: Auto LWE are inferred objects only, you cannot see them or edit them from Visual Studio.
Please refer to the Views and View Editor articles for more on this.
- Introduction
- Architect Guide
- Concepts
- Using Visual Studio
- Overview
- Creating a CodeModeler Project
- Visual Environment
- Project Hierarchy
- Design Surface
- Customizing Design Surfaces
- Ribbon Bar
- Property Grid
- Member Format Expressions
- Model Grid
- Method Editor
- View Editor
- Instance Editor and Grid
- Resources Editor
- Inferred Model Viewer
- Building
- Project Physical Layout
- Source Control Support
- Generating
- Aspect Oriented Design (AOD)
- Developer Guide
- The Business Object Model (BOM)
- CodeModeler Query Language (CMQL)
- Starting Guide - Tutorial
- Upgrade From CFE