2009-12-28 107 views
2

所以,我有以下表格:嵌套選擇在LLBLGEN

Tables

使用LLBLGEN 2.6(適配器版本 - 沒有LINQ),SQL Server和.NET 3.5,我怎麼會寫下面的查詢?

SELECT o.ObjectID 
FROM Object o 
INNER JOIN ObjectDetail d ON i.ObjectID = d.ObjectID 
WHERE d.CreatedDate = (SELECT MAX(CreatedDate) 
         FROM ObjectDetail 
         WHERE ObjectID = o.ObjectID 
        ) 

將會有更多的過濾,但它不是有關這一點,就像如果我有一個ObjectDetailType,我想最大ObjectDetail行某種類型。

此外,它不必選擇o.ObjectID,任何/所有列都可以。

回答

5

解決它

PredicateExpression.AddWithAnd(
    new FieldCompareSetPredicate(
    ObjectDetailFields.CreatedDate, 
    null, 
    ObjectDetailFields.CreatedDate.SetAggregateFunction(AggregateFunction.Max), 
    null, 
    SetOperator.Equal, 
    (ObjectFields.ObjectID == ObjectDetailsFields.ObjectID) 
) 
);