Yes, it's possible, you should use a ScalarQueryExpression in the filter. Here is an example, I want to fetch orders where their freight is the same to the max freight registered for the customer in the involved order:
// define the scalar field and filter
var scalarField = new EntityField2("MaxFreightFromCust",
new ScalarQueryExpression(OrderFields.Freight.SetObjectAlias("O2")
.SetAggregateFunction(AggregateFunction.Max),
(OrderFields.CustomerId.SetObjectAlias("O2") == OrderFields.CustomerId)));
var filter = new RelationPredicateBucket(OrderFields.Freight == scalarField);
// fetch
var orders = new EntityCollection<OrderEntity>();
using (var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(orders, filter);
}
Just apply the same concept to your scenario. The last parameter of the ScalarQueryExpression is the predicate expression of the query (the WHERE clause in your subquery), you can add many clauses to it, you can build it outside and pass the predicate to the constructor. Example:
var subqueryFilter = new PredicateExpression();
subqueryFilter.Add(OrderFields.CustomerId.SetObjectAlias("O2") == OrderFields.CustomerId);
subqueryFilter.Add(OrderFields.ShipDate.SetObjectAlias("O2") < DateTime.Now);
var scalarField = new EntityField2("MaxFreightFromCust",
new ScalarQueryExpression(OrderFields.Freight.SetObjectAlias("O2")
.SetAggregateFunction(AggregateFunction.Max),
subqueryFilter));