1) Open your model file

2) Add new operator

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

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

3) Setting operator's properties

ID: "DateWithinLastNDays"

This is mostly an 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 an operator. It defines the result expression which will come into generated SQL statement. and parts specify the operands. The first operand is always an attribute, second - some value entered by a 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 have the same kind and data type, but this preset can be changed. In our case, we need the second operand to be numeric (integer if more precisely) data type. To set it - just open “Operands” tab, select “Default operand” item in the list and choose “Int” in “Data type” combo box. All other operand properties let be left with their default values.

N.B.: 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 the 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:

open “Entities” tab

select necessary attribute

open its “Operators” tab

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:

We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.