Hi!
I'm looking for the correct LLBLGen code for this SQL:
SELECT * FROM customer c
LEFT OUTER JOIN order o ON o.customer = c.id
WHERE o.year = 2007 or o.id IS NULL
(Return all customer and their linked orders. Only return orders that have Year = 2007. Also return customers without orders.)
This is what I tried:
// create empty collection
EntityCollection<CustomerEntity> customers = new EntityCollection<CustomerEntity>(new CustomerEntityFactory());
// define prefetch path
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.CustomerEntity);
prefetchPath.Add(CustomerEntity.PrefetchPathOrder);
// focus on passed businessYear
RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.AddWithOr(OrderFields.Year == businessYear);
bucket.PredicateExpression.AddWithOr(OrderFields.Year == DBNull.Value);
// load data from db
Connection.GetDataAccessAdapter().FetchEntityCollection(customers, bucket, int.MaxValue, sorter, prefetchPath);
But this throws an exception because the resulting SQL is not as expected:
SELECT * FROM customer
WHERE order.year = 2007 or order.id IS NULL
That fails of course because the order table is missing.
What is the correct code in C#?
Thanks in advance!