EntityDAC

Specifying LINQ Query Arguments As String

There is another way to specify LINQ query arguments instead of using range variables and expressions.

In From and Join clauses that define the data source for the further query, the argument can be specified as a corresponding meta type name instead of a range variable.

Sample:

Linq.From('Emp')
    .Join('Dept')

In all clauses that require conditional arguments (On, Where, Any, All), the argument can be specified as a string containing Delphi-style conditional statement. In this case, every string constant inside the argument has to be additionally quoted. Otherwise, it will be treated as an meta-data identifier.

Sample:

Linq.From('Emp')
    .Join('Dept').On('Dept.DeptNo = Emp.DeptNo')
    .Where('(Emp.EmpNo > 100) and (Emp.EName <> ''Smith'')')

In clauses that accept either single or array-type arguments (GroupBy, OrderBy, ThenBy, Select), the string argument has to be specified using following rules.

Every string constant inside the argument has to be additionally quoted. Otherwise, it is treated as a meta-data identifier.

Sample:

Linq.From('Emp')
    .Select('''something''')
// will select the 'something' string
  
Linq.From('Emp')
    .Select('something')
// will try to select a list of the unknown 'something' meta type
// and raise the exception
  
Linq.From('Emp')
    .Select('Emp.EName')
// will select the list of Emp.EName values

If the string operand has to be specified as an array, the array brackets must be within the string. Otherwise, the argument is treated as an array with a single string element.

Sample:

Linq.From('Emp')
    .Select('[Emp.EmpNo, Emp.EName]')
// will select the list of Emp.EmpNo and Emp.EName values
  
Linq.From('Emp')
    .Select(['Emp.EmpNo, Emp.EName'])
// will try to select a list of 'Emp.EmpNo, Emp.EName' meta-data values
// and raise the exception
© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback