Creating an entity model using Quick Model
LLBLGen Pro contains a powerful, text DSL based modeling system called Quick Model. The Quick Model Editor is an editor to quickly specify definitions for relationships, entities and fields using a simple text DSL. You specify simple facts in text on a single line which are then processed and used to create a new element or execute a command. In the following tutorial we'll create a simple Customer - Order - OrderLine entity model using Quick Model.
Please note during the tutorial that the entity model lives in the Project, visible in the Project Explorer. This means that if you make changes in Quick Model, they're changes
to the Entity Model in the project: entities, fields etc. created in the Quick Model editor are immediately visible in the Project. There's intellisense implemented through
Ctrl-Space
and Ctrl-Shift-Space
. For deeper understanding of the Quick Model DSL, please see the
Quick Model section in the Designer documentation.
Using Quick Model
- Start the LLBLGen Pro designer. Either use the Programs start menu, Windows search or double click the LLBLGenPro.exe in the installation folder to start the LLBLGen Pro designer.
- To open our tutorial project, select it from the Recent Projects list on the Home Tab, or select File -> Open Project... from the main menu, or select the project from the File -> Recent Projects... menu.
- Open the Quick Model editor by selecting from the menu Project -> Quick Model Editor or press
F4
. The Quick Model editor tab opens. -
In the Command input are of the Quick Model editor you will specify the commands and facts, and thus also during this tutorial.
Every fact you type is ended with a carriage return which will make the editor to
interpret the fact and adjust the entity model accordingly. The model elements affected are included in the model view on the canvas above the command input.
Click in the Command input and type:
Customer.Orders 1n Order.Customer
, followed by pressingEnter
. This fact contains one relationship with two navigators and two entities. As none of them exists, the designer will create them for you. You should see two entities, Customer and Order on the modelview canvas with a 1:n relationship between them (Customer 1:n Order). -
To add fields to an entity, we have to specify the _scope* of our facts. In the step above we added the entities to the
empty group
scope. To add fields to a given entity we have to specify it as a scope. Type#u Customer
followed byEnter
. Active scope should now be set toCustomer
. - Type in the Command input the following statements, follow each line with an
Enter
. You can also copy/paste the lines below and pressEnter
after the last line to add all fields in one go.
Id int * CompanyName string(100) Address string(100) null City string(75) null Country string(50) null
-
The Customer entity now has a couple of fields, and the Order entity has received an FK field related to the PK field of Customer. Let's switch to Order by changing
the scope to the Order entity. To do that from within another scope we can specify the full name of the entity, which is groupname:entityname. As the group name is
empty, specify just
#u :Order
followed byEnter
. - Add the following fields to the Order entity, follow each line with an
Enter
. You can also copy/paste the lines below and pressEnter
after the last line to add all fields in one go.
Id int * OrderDate datetime ShippingDate datetime null
-
To add the last entity of the model, OrderLine we have to change the scope again, namely to the empty group. Do that by typing
#u-
to go up a scope. As we're in the Order scope, we go to its parent, the empty group. -
The OrderLine entity has a relationship with Order so it's the quickest to specify the relationship as it will automatically create the entities not already there.
Type
Order.OrderLines 1n OrderLine.Order
followed by pressingEnter
-
The designer has created a new relationship Order 1:n OrderLine, a new entity, OrderLine and reshuffeled the entities so they neatly line up. OrderLine has already
received the FK field related to Order.Id. To add more fields, first we'll move to the OrderLine scope, by typing
#u OrderLine
followed by pressingEnter
. - Type in the following lines to specify some fields in OrderLine, follow each line with an
Enter
. You can also copy/paste the lines below and pressEnter
after the last line to add all fields in one go.
Id int * Product string(100) Quantity int Price decimal(10,2)
- You now have an Entity Model with three entities and two relationships. Right-click Customer in the modelview on the Quick Model canvas and select Edit.... You can also right-click Customer in the Project Explorer and select Edit... from the context menu. The entity editor opens with the entity definition of Customer.
-
To illustrate everything views the same model inside the Designer, we're going to add a field to Customer and view it in the opened Customer editor. Keep the Entity editor
with Customer open and go back to the Quick Model tab using
Ctrl-Tab
. - Type
#u :Customer
to go to the Customer scope as we're going to add a field. -
Type
Zipcode string(10)
followed by pressingEnter
. The visual Entity in the modelview gets updated with the new field. Now pressCtrl-Tab
and go to the open entity editor with the Customer entity. The newly added field has been added to the grid, as it views the same model element: Customer. - Save your project, e.g. by using
Ctrl-S
.
Next step
The next step is adding a relational model data container for the relational model data created from the entity model and which will form your tables and constraints in the database: Add a relational model data container.