Hi Jose,
Are you using Adapter or SelfServicing?
What LLBLGen version are you using?
jselesan wrote:
ID VersionNumber
1 3
2 1
3 1
Maybe you meant:
ID VersionNumber
1 3
2 1
3 2
since, (2) is the last versionNumber for ID (3).
jselesan wrote:
I found this: http://stackoverflow.com/questions/1971801/nested-select-in-llblgen, but does not work because I need to refer to the same table
Any ideas?
It's different from the StackOverflow question, because your table is kind of an intermediate m:n, where your PK is composite (ID and VersionNumber). So the query you want to execute is something like:
SELECT * FROM CertificateEvents
WHERE VersionNumber =
(SELECT MAX(VersionNumber) FROM CertificateEvents C2
WHERE C2.Id = CertificateEvents.Id)
... to do that you need an ScalarQueryExpression in the filter. This is an approximate code:
var subqueryExp = new ScalarQueryExpression(
CertificateEventFields.VersionNumber
.SetObjectAlias("C2")
.SetAggregateFunction(AggregateFunction.Max),
(CertificateEventFields.Id.SetObjectAlias("C2") == CertificateEventFields.Id));
var filter = new RelationPredicateBucket(CertificateEventFields.VersionNumber == subqueryExp );
var certificates = new EntityCollection<CertificateEvent>();
using (var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(certificates, filter);
}
Hope helpful