Боюсь, ответ - нет, как вы и написали. Функция, которую вы показываете, использует функцию DataColumn в таблицах данных, свойство Expression .
По сути, он поддерживает многие операторы, которые вы найдете в SQL:
Из документации:
OPERATORS
Concatenation is allowed using Boolean AND, OR, and NOT operators. You can use parentheses to group clauses and force precedence. The AND operator has precedence over other operators. For example:
(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'
When creating comparison expressions, the following operators are allowed:
<
>
<=
>=
<>
=
IN
LIKE
The following arithmetic operators are also supported in expressions:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulus)
STRING OPERATORS
To concatenate a string, use the + character. Whether string comparisons are case-sensitive or not is determined by the value of the DataSet class's CaseSensitive property. However, you can override that value with the DataTable class's CaseSensitive property.
WILDCARD CHARACTERS
Both the * and % can be used interchangeably for wildcards in a LIKE comparison. If the string in a LIKE clause contains a * or %, those characters should be escaped in brackets ([]). If a bracket is in the clause, the bracket characters should be escaped in brackets (for example [[] or []]). A wildcard is allowed at the beginning and end of a pattern, or at the end of a pattern, or at the beginning of a pattern. For example:
"ItemName LIKE '*product*'"
"ItemName LIKE '*product'"
"ItemName LIKE 'product*'"
Wildcards are not allowed in the middle of a string. For example, 'te*xt' is not allowed.
PARENT/CHILD RELATION REFERENCING
A parent table may be referenced in an expression by prepending the column name with Parent. For example, the Parent.Price references the parent table's column named Price.
A column in a child table may be referenced in an expression by prepending the column name with Child. However, because child relationships may return multiple rows, you must include the reference to the child column in an aggregate function. For example, Sum(Child.Price) would return the sum of the column named Price in the child table.
If a table has more than one child, the syntax is: Child(RelationName). For example, if a table has two child tables named Customers and Orders, and the DataRelation object is named Customers2Orders, the reference would be:
Avg(Child(Customers2Orders).Quantity)
AGGREGATES
The following aggregate types are supported:
Sum (Sum)
Avg (Average)
Min (Minimum)
Max (Maximum)
Count (Count)
StDev (Statistical standard deviation)
Var (Statistical variance).
Aggregates are usually performed along relationships. Create an aggregate expression by using one of the functions listed above and a child table column as detailed in PARENT/CHILD RELATION REFERENCING above. For example:
Avg(Child.Price)
Avg(Child(Orders2Details).Price)
К сожалению, Square Root не является одной из функций, которые вы можете использовать. Однако, поскольку вы используете DataTable, вы можете просто циклически проходить по строкам и вычислять SquareRoot непосредственно из значения столбца. Представьте, что у вас есть столбец под названием «MyNumber». Затем вы можете сделать что-то вроде:
myDataTable.Columns.Add(new DataColumn() { Name = "MySquareRoot", DataType = typeof(Double)});
foreach(DataRow row in myDataTable.Rows)
{
myDataTable["MySquareRoot"] = Math.Sqrt(Convert.ToDouble(myDataTable["MyNumber"]));
}
Вы можете поместить такую функцию в метод Extension , если хотите.
В качестве альтернативы, вы можете использовать свои формулы где-то еще; вместо того, чтобы использовать DataTable для моделирования ваших данных, вы можете использовать класс. Сам класс может иметь свойства (или список или коллекцию), которые представляют ваши данные, и методы, которые воздействуют на ваши данные - тогда вы можете использовать любую функцию, какую захотите, в C #.