use case is this
Our partner creates a custom made script (using TMS Scripter) for customers.
Some cases customer has xdataserver in infrastructure and in some cases not. (depending on customer)
If would like to provider our partner simple method for searching customer in script code like
lCustomerlist := CustomerModule.SearchCustomers('email eq ''mika@skj.fi''');
is it possible to use xdata's queryparser to transform query to aurelius criteria?
(with reasonable work)
my other option is to force local xdataserver installation.
You can see that you can create an Aurelius criteria from a XData query. Such code is attached to XData, but if you check the actual implementation of such CreateCriteria<T> method (in unit XData.Server.Module), you will see it's relatively simple and you can copy/paste the code and adapt to your needs to create criteria from XData query:
function TXDataOperationContext.CreateCriteria<T>(Manager: TObjectManager; Query: TXDataQuery;
Model: TXDataAureliusModel; BaseType: TXDataStructuredType): TCriteria<T>;
var
QueryInfo: TXDataQueryInfo;
Builder: TXDataCriteriaBuilder;
TargetType: TXDataEntityType;
begin
TargetType := Model.GetEntityTypeByClass(T);
if BaseType = nil then
BaseType := TargetType;
QueryInfo := TXDataQueryInfo.Create(BaseType, Query);
try
QueryInfo.Solve;
Builder := TXDataCriteriaBuilder.Create(Model, QueryInfo);
try
Result := Manager.Find<T>;
try
Builder.UpdateCriteria(Result);
except
Result.Free;
raise;
end;
finally
Builder.Free;
end;
finally
QueryInfo.Free;
end;
end;
thanks for this.
I have tried to implement this, seem very simple.
But how to initialize Model correctly?
I have used lModel:= TXDataAureliusModel.create;
Entities are in default model.
Model.GetEntityTypeByClass(t) raises exception EXDataEntityTypeFromClassNotFound
Entity type not found for class "TCustomer"
While debugging I found than model.Schemas is empty.
My scripting application knows entities . I checked it byt calling objectmanager.find(tcustomer,1) in my script befor other operations.
So I think I'm missing something from initialization.