views:

39

answers:

1

Hi All,

I want to do something like this...

SELECT DISTINCT T1.* 
FROM T1 
INNER JOIN T2 ON T2.ID1 = T1.ID1
INNER JOIN T3 ON T3.ID2 = T2.ID2
--FOLLOWING CAN BE ADDED MULTIPLE TIMES  (LOOPS IN C#?)
INNER JOIN T2 AS T2A ON T3.ID2 = T2A.ID2
INNER JOIN T1 AS T1A ON T1A.ID1 = T2A.ID1
--END MULTI
WHERE T1.ID1 = 1
AND T3.ID3 = 2
AND T3.ID4 = 3
--THE FOLLOWING CONDITIONS WILL ALSO BE FOR EVERY SET OF EXTRA JOINS (LOOPS IN C#?)
AND T1A.ID1 = 4
AND T1I.ID5 = 5
--END MULTI

...in either Linq or LLBLGen Code. Any help would be greatly appreciated!

Here is the LLBGen I have so far...

            IPredicateExpression filter = new PredicateExpression();
            filter.Add(ProductTypeOptionAttributeFields.OptionId == dl.Key);
            filter.AddWithAnd(ProductTypeOptionAttributeCombinationFields.ProductTypeId == DataSource.DataItem.ProductTypeId);
            filter.AddWithAnd(ProductTypeOptionAttributeCombinationFields.ProductId == DataSource.ProductID);
            bucket.PredicateExpression.Add(filter);

            bucket.Relations.Add(ProductTypeOptionAttributeEntity.Relations.ProductTypeOptionAttributeCombinationProfileEntityUsingProductTypeOptionAttributeId, JoinHint.Inner);
            bucket.Relations.Add(ProductTypeOptionAttributeCombinationProfileEntity.Relations.ProductTypeOptionAttributeCombinationEntityUsingProductTypeOptionAttributeCombinationId, JoinHint.Inner);

            var filtered = _dropdowns.Where(k => ((DropDownList)k.Value[1]).SelectedValue != "-1" && k.Key != dl.Key);
            foreach (var filteredDdl in filtered)
            {

                IPredicateExpression subFilter = new PredicateExpression();
                subFilter.AddWithAnd(ProductTypeOptionAttributeFields.AttributeId == int.Parse(((DropDownList)filteredDdl.Value[1]).SelectedValue));
                subFilter.AddWithAnd(ProductTypeOptionAttributeFields.OptionId == filteredDdl.Key);
                bucket.PredicateExpression.AddWithAnd(subFilter);                    
            }


            ProductTypeOptionAttributeCollection attrs = new ProductTypeOptionAttributeCollection();
            attrs.GetMulti(bucket.PredicateExpression, -1, null, bucket.Relations);

And here is the actual query I want...

    SELECT DISTINCT PTOA.* 
    FROM ProductTypeOptionAttribute AS PTOA
    INNER JOIN ProductTypeOPtionAttributeCombinationProfile AS PTOACP ON PTOACP.ProductTypeOPtionAttributeID = PTOA.AttributeID
    INNER JOIN ProductTypeOPtionAttributeCombination AS PTOAC ON PTOAC.CombinationID = PTOACP.ProductTypeOptionAttributeCombinationID
    --FOLLOWING CAN BE ADDED MULTIPLE TIMES  (LOOPS IN C#?)
    INNER JOIN ProductTypeOPtionAttributeCombinationProfile AS PTOACP2 ON PTOAC.CombinationID = PTOACP2.ProductTypeOptionAttributeCombinationID
    INNER JOIN ProductTypeOPtionAttribute AS PTOA2 ON PTOACP2.ProductTypeOPtionAttributeID = PTOA2.AttributeID
--END MULTI
    WHERE PTOA.OptionID = 59
    AND PTOAC.ProductTypeID = 11

AND PTOAC.ProductID = 218
--THE FOLLOWING CONDITIONS WILL ALSO BE FOR EVERY SET OF EXTRA JOINS (LOOPS IN C#?)
AND PTOA2.AttributeID = 42
AND PTOA2.OptionID = 58
--END MULTI

Cheers