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

This is an old revision of the document!


How to add new operator into your data model

Each data model contains a lot of default operators. However sometimes you may need to add a new operator into your model.

Let's suppose we need “within last N days” operator which words for date/time fields, takes a numeric operand (N) and returns true if specified date is within last N days starting from today.

Here are the instructions:

1. Open your model file

Run Data Model Editor utility (DME) and open your model (.xml) file (Model | Open… menu item).

2. Add new operator

Go to Operators tab and select “Operators | Add Operator” menu item. New operator with default ID “NewOp” will will appear at the bottom of the list of operators.

After that we need to define all properties for new operator.

3. Setting operator's properties

ID: "DateWithinLastNDays"

This is mostly internal property. EasyQuery will use to reference this operator in attributes and query conditions.

Caption: "Last N days"

This value will be shown to users in a drop-down list when they select operator

Display format: "{expr1} [[is within last]] {expr2} days"

This field defines how your operator (actually the whole condition with this operator) will look in a condition row in query panel. The part within [[ and ]] will be clickable.

Expression: "{expr1} > DATEADD(day, -{expr2}, GETDATE())"

The most important property for operator. It defines the result expression which will come into generated SQL statement. {expr1} and {expr2} parts specify the operands. First operand is always an attribute, second - some value entered by user.

Applied types: "Date, DateTime"

Since this operator can be used only with Date and DateTime attributes - we uncheck all options in “Applied types” field except these two.

Here is how Operators tab in DME looks like after all changes described above:

4. Setting operand's properties

Each operator has one or more operands. By default all operands has the same kind and data type but this preset can be changed. In our case we need second operand to be numeric (integer if more precisely) data type. To set it - just open “Operands” tab, select “Default operand” item in list and choose “Int” in “Data type” combo box. All other operand properties let be left with their default values.

NB: By default “data type” property has “Auto” value. It means that this operand will have the same type as attribute selected for the left part of condition. It's useful for operators which can be applied to attributes with different data types (e.g. “is equal to”).

5. Associate new operator with attribute(s)

Finally, we need to associate new operator with one or more attributes for which it may be used in query conditions. To do it:

  1. open “Entities” tab
  2. select necessary attribute
  3. open its “Operators” tab
  4. click on “Add” button, check new operator and click OK.

6. Done!

Finally save your model and run the project which uses this model to test new operator:

Discussion

Enter your comment: