Back to
Latest changes:
2020/01/13 19:15

This is an old revision of the document!


Virtual attributes

What are they for

There are 2 types of entity attributes in each data model:

  • data attributes which are based on corresponding fields (columns) of some database table. At the beginning all attributes in your model are “data atttributes”. They are created automatically by meta-information of your database.
  • virtual attributes - are actually a kind of calculated columns. For example you can create a “Full name” attribute for your “Employee” entity and define its expression like Employees.FirstName + ' ' + Employees.LastName

The main advantage of virtual attribute is that your will not need to type full expression each type they would like to see such column in result set or to use that expression in a query condition. They just can select this attribute (either in columns or conditions) the same way as they do for any other entity attribute in your model. EasyQuery will do the rest of the jobs automatically: it will add necessary table(s) into result SQL, join them with other tables used in that query and add the expression defined for virtual attribute either in SELECT or WHERE clause.

How to add

1. Run Data Model Editor and open your model there.

2. Go to the Entities tab and select the entity node where you would like to add new virtual attribute.

3. Right click on that node and select “Add virtual attribute” menu item.

4. Then you will need to define main properties of new attribute:

  • Caption - it's then name with which this attribute will be presented to your end-users (when they select it in Columns or Conditions sections). Its “Full Name” in our example above.
  • Expression - the exact SQL expression which is used in result SQL statement in the place of this attribute. It must include full field names include table (like “Employees.FirstName” in our example).
  • Used tables - it's the list of tables used in this attribute's expression. This list should be filled automatically when you entered the expression. If not - add table(s) manually used “Add” button.
  • Data type - it's important to set a correct data type for new attribute so it will be correctly processed during SQL generation (quotes, formats, etc).
  • “Other options” section - it's the same as for data attribute. You can disable your new attribute for Conditions section (uncheck “Use in conditions” mark) or for Columns (“Use in result”). You can also mark it as “aggregate” - so EasyQuery will automatically add “GROUP BY” clause when this attribute is used in Columns section.
  • Description - any text which describe your attribute. The value of this field can be shown as a tooltip when user moves mouse cursor over corresponding entity node in Entities Panel.

5. Finally you need to define the list of operators which can be used with your attribute in conditions. Open “Operators” tab for your attribute (don't confuse it with global Operators tab - the one you need is inside “Entity / attribute properties” panel) and click on “Defaults” button to get default list of operators suitable for this attribute. Of course you can skip this step of you don't plan to use this attribute in conditions (“Use in conditions” option is turned off).

6. That's all. Save your model and tell you users about new attribute they can use in their queries.

Discussion

Enter your comment: