4

我有以下 Sql 查询,它返回我想要的结果类型:

SELECT b.ID, a.Name, b.Col2, b.COl3
FROM Table1 a
LEFT OUTER JOIN Table2 b on b.Col4 = a.ID AND b.Col5 = 'test'

本质上,我希望行数等于表 1 (a),同时列出表 2 (b) 中的数据,如果条件“测试”在表 2 中不存在,则为 NULL。

我对 LLBLGen 很陌生,并且尝试了一些东西,但它不起作用。如果条件存在,我可以让它工作;但是,当需求发生变化并导致我将查询重写为上述查询时,我不知所措。

以下是适用于现有产品但不适用于上述查询的旧 LLBLGen C# 代码:

LookupTable2Collection table2col = new LookupTable2Collection();

RelationCollection relationships = new RelationCollection();
relationships.Add(LookupTable2Entity.Relations.LookupTable1EntityUsingTable1ID, JoinHint.Left);

IPredicateExpression filter = new PredicateExpression();
filter.Add(new FieldCompareValuePredicate(LookupTable2Fields.Col5, ComparisonOperator.Equal, "test"));

table2col.GetMulti(filter, relationships);

表 1 中有 3 条记录。即使表 2 中的所有项目都为 NULL,我也需要返回 3 条记录,因为条件不存在。有任何想法吗?

4

1 回答 1

7

您必须像这样将过滤器添加到关系联接中:

relationships.Add(LookupTable2Entity.Relations.LookupTable1EntityUsingTable1ID, JoinHint.Left).CustomFilter = new FieldCompareValuePredicate(LookupTable2Fields.Col5, ComparisonOperator.Equal, "test");
于 2009-03-31T22:22:50.207 回答