QueryString from Tcriteria

I have a Tcriteria created for using it with a Tobjectmanager object.

cr:=objectManager.Find<TCustomer>.where(
(Linq['Name'] = 'Paul')
or (Linq['Birthday'] < EncodeDate(1940, 8, 1))
)
.OrderBy('Name', False);

Can I use the cr again in the following Xdata client code, without rewriting it?

Customers := Client.List<TCustomer>(
CreateQuery
.From(TCustomer)
.Filter(
(Linq['Name'] = 'Paul')
or (Linq['Birthday'] < EncodeDate(1940, 8, 1))
)
.OrderBy('Name', False)
.QueryString
);

The idea behind this question is to create a Tcriteria that can be used either for a local db with Tobjectmanager or with a Xdata server through Xdata client.
Is it posible to convert a generic version of Tcriteria to the non-generic version without using Subcriteria?

Except above the following code does not work if cr:Tcriteria has associations (with CreateAlias):

var f:IXDataQueryBuilder;
f:=CreateQuery.From(Tcustomer);
for var c in cr.Criteria do
   f.Filter(c);
s:=f.QueryString;

Indeed, the XData query is slightly different from the one in Aurelius. You don't provide aliases to it, so filters that reference alias won't work. In XData query, the fields must reference the properties directly, like Linq['Invoice.Customer.Name'] = 'John'.

So they won't work. But other than this, you should be able to use the same filter, indeed. I just suggest you use Clone method because both Aurelius criteria and XData query builder will destroy the underlying filter object, thus if you add the same instance to both, you will end up with an invalid point exception due to double destruction:

var f:IXDataQueryBuilder;
f:=CreateQuery.From(Tcustomer);
for var c in cr.Criteria do
   f.Filter(c.Clone);
s:=f.QueryString;
2 Likes

As I can see in documentation, It is not possible to run a query with Tprojections or with multiple tables/entities in Xdata.
Is it possible to pass somehow a Tcriteria to a service function to be run as aurelius query in the server?
There is a SaveToJSONStream in Tcriteria, can I pass it as a stream?

PS I just noticed that SaveToJSONStream is a Tobject helper from FMX.TMSFNCTypes. Is there a way to "send" the Tcriteria to the server to be used by Tobjectmanager?

The XData query (and query builder) are already tools to pass a "criteria" to XData service. There is no current feature to pass a full "Aurelius criteria" to it, though, as it would be the (almost) equivalent to pass a full SQL statement to the server.

1 Like

The idea behind my question is the following:
As a TMS Xdata consumer, I am focused on reusable code that could be used in multiple cases. I loved the the CreateQuery feature and I though I could reuse the code that I am already using in Taurelius.
But it is OK.

1 Like