Sorry for the lack of information previously - I hope this is better...
As before - using llblgen 2.0, .Net 1.1, Self Servicing
I am performing a GetMulti on a ProductCollection object, passing in PredicateExpression and RelationCollection that have been built by calling AddFilter methods on various objects.
public void AddFilter(ref PredicateExpression predicate, ref RelationCollection relations, IInputObject input, bool negativeFilter,bool source)
{
try
{
if (source)
{
//calculate the ltv
double ltv=(input.LoanSize/input.Valuation)*100;
//Flat
if(input.PropertyType[0]==Enums.PropertyTypeStringConstants.Flat)
{
PredicateExpression pe =new PredicateExpression();
pe.Add(MaxltvforflatFields.Storeys >= input.FloorNumber);
relations.Add(ProductEntity.Relations.Lender2EntityUsingLender2Id);
relations.Add(Lender2Entity.Relations.MaxltvforflatEntityUsingLender2Id).CustomFilter=pe;
predicate.AddWithAnd(MaxltvforflatFields.MaxLtv >= ltv);
}
}
}
catch(Exception ex)
{throw ex;}
}
The code that calls this is similar to:
ProductCollection products=new ProductCollection();
PredicateExpression pe=new PredicateExpression();
RelationCollection relations=new RelationCollection();
//
//Code to call filter objects passing refs to pe and relations
//
products.GetMulti(pe,relations);
The table structure is as follows:
LENDER2 (Lender2Id(pk), ...)
PRODUCT (ProductID(pk), Lender2ID(fk for LENDER2), ...)
MAXLTVFORFLAT(FlatId(pk), Lender2ID(fk for LENDER2), Tier, Storeys, MaxLtv)
The SQL required to perform the filter would be similar to this...
Select top 1 MAXLTVFORFLAT.MaxLTV from MAXLTVFORFLAT where
MAXLTVFORFLAT.lender2id =
(Select LENDER2.lender2id From LENDER2 Where LENDER2.Lender2Id in
(Select PRODUCT.Lender2Id from PRODUCT where PRODUCT.ProductId='x')) AND MAXLTVFORFLAT.MaxLTV > 'y'
order by Tier
... where 'y' is the 'ltv' variable in my code below and 'x' represents the 'ProductId' for the current ProductEntity
Basically, my current code is missing the 'Top 1' and 'order by Tier' parts of the SQL so returns multiple rows where I only want one - but I can't see any way of adding this to the current code. I could just add another field to the table if necessary so I can specify a min and max number for 'Storeys' and change the custom filter predicate to a FieldBetweenPredicate but I was hoping not to.