Hi,
I am trying to generate below SQL to LLBLGen for Audit purpose
SELECT
a.ebaDateTime,
a.ebaOperationGUID,
a.ebaByFullName,
a.ebaAuditTypeDescription,
a.ebaData,
a.ebaAuditIsDeleted,
b.ebdEmployeeId
FROM dbo.inkEmployeeBankAudit a
LEFT JOIN dbo.inkEmployeeBank b
ON b.ebdEmployeeBankId = a.ebaEmployeeBankId
** AND** b.ebdEmployeeId = @EmployeeId;
I have spent 45 minutes to one hour on ChatGPT and Grok. Thay provided various answers and none of them worked due to no WHERE in SQL but it has AND
Can you please provide LLBLGen query using API (old way) not in LINQ or queryspecs.
Below is one of the example that AI suggested.
// 1. Define fields to fetch
IEntityField2[] fields = new IEntityField2[]
{
InkEmployeeBankAuditFields.EbaDateTime,
InkEmployeeBankAuditFields.EbaOperationGUID,
InkEmployeeBankAuditFields.EbaByFullName,
InkEmployeeBankAuditFields.EbaAuditTypeDescription,
InkEmployeeBankAuditFields.EbaData,
InkEmployeeBankAuditFields.EbaAuditIsDeleted,
InkEmployeeBankFields.EbdEmployeeId // from joined table
};
// 2. Create the bucket
IRelationPredicateBucket bucket = new RelationPredicateBucket();
// 3. Create a dynamic relation (source: audit, target: bank)
DynamicRelation auditToBank = new DynamicRelation(typeof(InkEmployeeBankEntity))
{
JoinHint = JoinHint.Left
};
// 4. Set source entity and ON clause
auditToBank.SourceEntityType = typeof(InkEmployeeBankAuditEntity); // source table
PredicateExpression onClause = new PredicateExpression();
onClause.Add(InkEmployeeBankFields.EbdEmployeeBankId == InkEmployeeBankAuditFields.EbaEmployeeBankId);
onClause.AddWithAnd(InkEmployeeBankFields.EbdEmployeeId == employeeId); // extra ON filter
auditToBank.OnClause = onClause;
// 5. Add relation to the bucket
bucket.Relations.Add(auditToBank);
// 6. Fetch results
DataTable results = new DataTable();
using (var adapter = new DataAccessAdapter())
{
adapter.FetchTypedList(fields, results, bucket, allowDuplicates: true);
}
in sort want to generate instead 'AND' in SQL instead of WHERE