Help required with FieldCompareSetPredicate

Posts   
 
    
Posts: 48
Joined: 26-Mar-2007
# Posted on: 23-Nov-2007 13:26:15   

LLBLGENPro 2.5Final Adapter C# .Net 2.0

Schema looks like:

J --> P --> PS P --> PT

where: J - Job P - Parameter PT - ParameterType PS - ParameterString

J --> P 1:m P --> PT n:1 P --> PS sub class relationship

Each job has a collection of parameters (the parameters are subclassed based on data type and here I am showing only the string parameters) If a parameter value is changed the value is not overwritten but a new ParameterEntity created and the value stored there thus the current parameter value is the highest parameter id for all parameters with the same ParameterType (this allows us to see a history of changes).

What I am tying to do is fetch a collection of Jobs where the current ParameterString of a certain type is a given value

e.g ParameterType has Name='JobCode' and ParameterString as Value='L001'

In SQL I would write something like:

SELECT   dbo.Job.Id AS JobId
FROM    Job as J INNER JOIN
             Parameteras P  ON dbo.Job.Id = P.JobFk INNER JOIN
             ParameterString as PS ON P.Id = PS.Id INNER JOIN
             JobTypeParameter as JTP ON P.JobTypeParameterFk = JTP.Id
WHERE JTP.Name='JobCode' AND
      PS.Value='L001' AND
dbo.Parameter.Id IN
(
SELECT   top 1 P2.Id
FROM    Job as J2 INNER JOIN
             Parameter as P2 ON J2.Id = P2.JobFk INNER JOIN
             JobTypeParameter as JTP2 ON P2.JobTypeParameterFk = JTP2.Id
WHERE JTP2.Name=JTP.Name AND J2.Id=J.Id
ORDER BY P2.Id DESC
)
ORDER BY dbo.Job.Id

I tried writing a pedicate to do this but got stuck writing the IN portion

bucket.Relations.Add(JobEntity.Relations.ParameterEntityUsingJobFk);
    bucket.Relations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk);

    FieldCompareValuePredicate jobCodeNameMatchPredicate = new FieldCompareValuePredicate(JobTypeParameterFields.Name, null, ComparisonOperator.Equal, "JobCode");
    jobCodeNameMatchPredicate.CaseSensitiveCollation = true;
    bucket.PredicateExpression.Add(jobCodeNameMatchPredicate);

    FieldCompareValuePredicate jobCodeValueMatchPredicate = new FieldCompareValuePredicate(ParameterStringFields.Value, null, ComparisonOperator.Equal, "L001");
    jobCodeValueMatchPredicate.CaseSensitiveCollation = true;
    bucket.PredicateExpression.Add(jobCodeValueMatchPredicate);

    FieldCompareSetPredicate fieldCompareSetPredicate = new FieldCompareSetPredicate(
        ParameterFields.Id,
        null,
        ParameterFields.Id,
        SetOperator.In, inPredicate);

Am I heading in the right direction here? Any help gratefully received

--Sam

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Nov-2007 15:37:12   

dbo.Parameter.Id IN ( SELECT top 1 P2.Id FROM Job as J2 INNER JOIN Parameter as P2 ON J2.Id = P2.JobFk INNER JOIN JobTypeParameter as JTP2 ON P2.JobTypeParameterFk = JTP2.Id WHERE JTP2.Name=JTP.Name AND J2.Id=J.Id ORDER BY P2.Id DESC )

1- You have JOINs in the above Sub-Query so you should specify the corresponding Relations in an overload of the FieldCompareSetPredicate which accept a RelationCollection.

2- There is a filtering Condition within the Sub-Query, same way you need to specify the corresponding PredicateExpression in the FieldCompareSetPredicate .

3- The mentioned filtering condition involves a field of a table from the outer Query, and that table is Joined again in the Sub-Query, so you need to deferentiate between both instances by using an Alias, as you did in your SQL statement. But only one Alias on one of those instances is sufficient.

4- I recommend to leave the outer Query intact and add that Alias to the JobTypeParameter Entity Joined in the Sub-Query. For this you will need to Specify the Alias in an overload of the Relations.Add() method which specify the Join of the JobTypeParameter in the Sub-Query. Also you will need to use this same Alias in the PredicateExpression (WHERE) used in the Sub-Query. (The Same thing applies for the Job Entity)

5- Finally you will need to specify the SortExpression and maxNumberOfItemsToReturn for OrderBy and Top 1 .

Following is the overloaded CTor you need to use for the FieldCompareSetPredicate:

public FieldCompareSetPredicate( 
   IEntityFieldCore field,
   IFieldPersistenceInfo persistenceInfoField,
   IEntityFieldCore setField,
   IFieldPersistenceInfo persistenceInfoSetField,
   SetOperator operatorToUse,
   IPredicate filter,
   IRelationCollection relations,
   string objectAlias,
   long maxNumberOfItemsToReturn,
   ISortExpression sorter
)
Posts: 48
Joined: 26-Mar-2007
# Posted on: 23-Nov-2007 17:17:09   

Thanks that helps a lot, but I'm still not quite there

this is what I came up with:


                    bucket.Relations.Add(JobEntity.Relations.ParameterEntityUsingJobFk);
                    bucket.Relations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk);

                    FieldCompareValuePredicate jobCodeNameMatchPredicate = new FieldCompareValuePredicate(JobTypeParameterFields.Name, null, ComparisonOperator.Equal, "JobCode");
                    jobCodeNameMatchPredicate.CaseSensitiveCollation = true;
                    bucket.PredicateExpression.Add(jobCodeNameMatchPredicate);

                    FieldCompareValuePredicate jobCodeValueMatchPredicate = new FieldCompareValuePredicate(ParameterStringFields.Value, null, ComparisonOperator.Equal, filter.JobCode);
                    jobCodeValueMatchPredicate.CaseSensitiveCollation = true;
                    bucket.PredicateExpression.Add(jobCodeValueMatchPredicate);

                    RelationCollection inRelations = new RelationCollection();
                    inRelations.Add(JobEntity.Relations.ParameterEntityUsingJobFk, "J2");
                    inRelations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk, "JTP2");

                    PredicateExpression inPredicate = new PredicateExpression();

                    FieldCompareExpressionPredicate fieldJTPNamePredicate = new FieldCompareExpressionPredicate(
                            JobTypeParameterFields.Name,
                            null,
                            ComparisonOperator.Equal,
                            new Expression(JobTypeParameterFields.Name), "JTP2");

                    inPredicate.Add(fieldJTPNamePredicate);

                    FieldCompareExpressionPredicate fieldJIdPredicate = new FieldCompareExpressionPredicate(
                            JobFields.Id,
                            null,
                            ComparisonOperator.Equal,
                            new Expression(JobFields.Id), "J2");

                    inPredicate.Add(fieldJIdPredicate);

                    SortExpression inSorter = new SortExpression(ParameterFields.Id | SortOperator.Descending);

                    FieldCompareSetPredicate fieldCompareSetPredicate = new FieldCompareSetPredicate(
                        ParameterFields.Id,
                        null,
                        ParameterFields.Id,
                        null,
                        SetOperator.In,
                        inPredicate,
                        inRelations,
                        null,
                        1,
                        inSorter);

                    bucket.PredicateExpression.Add(fieldCompareSetPredicate);

However this gives me this error on the fetch:

Message:Relation at index 1 doesn't contain an entity already added to the FROM clause. Bad alias? Source: SD.LLBLGen.Pro.ORMSupportClasses.NET20 TargetSite: ToQueryText

I guess it is my "J2" alias but I can't see how to formulate it correctly

Cheers!

--Sam

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Nov-2007 02:48:53   

Could your try replace this

inRelations.Add(JobEntity.Relations.ParameterEntityUsingJobFk, "J2");                   
inRelations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk, "JTP2");

with this

inRelations.Add(JobEntity.Relations.ParameterEntityUsingJobFk, "J2");                   
inRelations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk, "J2", "JTP2", JoinHint.INNER);

Also, could you please inspect the generated SQL code in that fetch and post here? (LLBLGen Help - Using generated code - Troubleshooting and debuging).

David Elizondo | LLBLGen Support Team
Posts: 48
Joined: 26-Mar-2007
# Posted on: 26-Nov-2007 10:44:02   

That gives me this:

System.NullReferenceException occurred
  Message="Object reference not set to an instance of an object."
  Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20"
  StackTrace:
       at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.ConvertFieldToRawName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction)
       at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction)
       at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareSetPredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
       at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
       at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
       at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker)
       at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified)
       at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause)
       at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateSelectDQ(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfoObjects, IPredicateExpression filter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath)
       at Cwc.WaterWorks.ServiceLayer.WaterWorksServiceLayer.GetJobsForList(EntityCollection`1 jobs, JobFilter filter, Int32 maxCount) in C:\work\WorkManagement\RC1\WaterWorksServiceLayer\Job.cs:line 358

I'll try and get you some generated SQL

Posts: 48
Joined: 26-Mar-2007
# Posted on: 26-Nov-2007 11:10:41   

I turned-up all the tracing levels to 4, but I can't see any SQL related to this filter, just the existing working filter just before I turned on this new one.

--Sam

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Nov-2007 07:53:55   

Looking closely I found some alias problems, I rewrote a little your code, here is the relevant part:

RelationCollection inRelations = new RelationCollection();
inRelations.Add(JobEntity.Relations.ParameterEntityUsingJobFk, "J2", "P2", JoinHint.Inner);
inRelations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk, "P2", "JTP2", JoinHint.Inner);

PredicateExpression inPredicate = new PredicateExpression();

FieldCompareExpressionPredicate fieldJTPNamePredicate = new FieldCompareExpressionPredicate(
        JobTypeParameterFields.Name,
        null,
        ComparisonOperator.Equal,
        JobTypeParameterFields.SetObjectAlias("JTP2") );
inPredicate.Add(fieldJTPNamePredicate);

FieldCompareExpressionPredicate fieldJIdPredicate = new FieldCompareExpressionPredicate(
        JobFields.Id,
        null,
        ComparisonOperator.Equal,
        JobFields.Id.SetObjectAlias("J2") );
inPredicate.Add(fieldJIdPredicate);

SortExpression inSorter = new SortExpression( new SortClause(ParameterFields.Id.SetObjectAlias("J2"), null, SortOperator.Descending));

FieldCompareSetPredicate fieldCompareSetPredicate = new FieldCompareSetPredicate(
    ParameterFields.Id,
    null,
    ParameterFields.Id.SetObjectAlias("J2"),
    null,
    SetOperator.In,
    inPredicate,
    inRelations,
    null,
    1,
    inSorter);

bucket.PredicateExpression.Add(fieldCompareSetPredicate);

Please let me know if that made it wink

David Elizondo | LLBLGen Support Team
Posts: 48
Joined: 26-Mar-2007
# Posted on: 27-Nov-2007 11:41:28   

Well that doesn't compile, the FieldCompareExpressionPredicate construction parameters are not matching, SetObjectAlias does not return an IExpression

e.g.

FieldCompareExpressionPredicate fieldJTPNamePredicate = new FieldCompareExpressionPredicate(
        JobTypeParameterFields.Name,
        null,
        ComparisonOperator.Equal,
        JobTypeParameterFields.SetObjectAlias("JTP2") );

I don't understand the use of SetObjectAlias here

--Sam

Posts: 48
Joined: 26-Mar-2007
# Posted on: 27-Nov-2007 12:32:27   

I tried it like this:

                    FieldCompareExpressionPredicate fieldJTPNamePredicate = new FieldCompareExpressionPredicate(
                            JobTypeParameterFields.Name,
                            null,
                            ComparisonOperator.Equal,
                            new Expression(JobTypeParameterFields.Name.SetObjectAlias("JTP2")), "JTP2");

                    inPredicate.Add(fieldJTPNamePredicate);

                    FieldCompareExpressionPredicate fieldJIdPredicate = new FieldCompareExpressionPredicate(
                            JobFields.Id,
                            null,
                            ComparisonOperator.Equal,
                            new Expression(JobFields.Id.SetObjectAlias("J2")), "J2");

but that still gives the same null ref error

--Sam

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Nov-2007 11:56:52   

I think any of the following should work:

FieldCompareExpressionPredicate fieldJTPNamePredicate = new FieldCompareExpressionPredicate(
        JobTypeParameterFields.Name,
        null,
        ComparisonOperator.Equal,
        new Expression (JobTypeParameterFields.Name.SetObjectAlias("JTP2") ));

EntityField2 jtpName = JobTypeParameterFields.Name;
jtpName.SetObjectAlias("JTP2");

FieldCompareExpressionPredicate fieldJTPNamePredicate = new FieldCompareExpressionPredicate(
        JobTypeParameterFields.Name,
        null,
        ComparisonOperator.Equal,
        new Expression (jtpName));
FieldCompareExpressionPredicate fieldJTPNamePredicate = new FieldCompareExpressionPredicate(
                            JobTypeParameterFields.Name,
                            null,
                            ComparisonOperator.Equal,
                            new Expression(JobTypeParameterFields.Name), "JTP2");

Just note the alias parameter used in the last example will alias the field passed in the first parameter, which won't make a difference in our case.

Posts: 48
Joined: 26-Mar-2007
# Posted on: 28-Nov-2007 12:54:39   

Yes that is basically what I have tried, however they do not solve the main issue with the Null Reference crash when I call the fetch.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Nov-2007 15:42:30   

I think it would hard for us to help you without a repro solution. Would you please attach a simple repro solution based on Northwind database, or on your own schema (in this case attach the DB script).

Thanks.

(EDIT) I'm looking into it, aliases are mixed out. I'll get back to you asap.

(EDIT)

SELECT dbo.Job.Id AS JobId FROM Job as J INNER JOIN Parameteras P ON dbo.Job.Id = P.JobFk INNER JOIN ParameterString as PS ON P.Id = PS.Id INNER JOIN JobTypeParameter as JTP ON P.JobTypeParameterFk = JTP.Id WHERE JTP.Name='JobCode' AND PS.Value='L001' AND dbo.Parameter.Id IN ( SELECT top 1 P2.Id FROM Job as J2 INNER JOIN Parameter as P2 ON J2.Id = P2.JobFk INNER JOIN JobTypeParameter as JTP2 ON P2.JobTypeParameterFk = JTP2.Id WHERE JTP2.Name=JTP.Name AND J2.Id=J.Id ORDER BY P2.Id DESC ) ORDER BY dbo.Job.Id

What I am tying to do is fetch a collection of Jobs where the current ParameterString of a certain type is a given value

e.g ParameterType has Name='JobCode' and ParameterString as Value='L001'

ResultsetFields fields = new ResultsetFields(1);
fields.DefineField(JobFields.Id, 0, "JobId");

IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(JobEntity.Relations.ParameterEntityUsingJobFk);
bucket.Relations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk);

// Filter on the entity type of the ParameterString SubType.
bucket.PredicateExpression.Add(ParameterStringEntity.GetEntityTypeFilter());

FieldCompareValuePredicate jobCodeNameMatchPredicate = new FieldCompareValuePredicate(JobTypeParameterFields.Name, null, ComparisonOperator.Equal, "JobCode");
    jobCodeNameMatchPredicate.CaseSensitiveCollation = true;
    bucket.PredicateExpression.Add(jobCodeNameMatchPredicate);

FieldCompareValuePredicate jobCodeValueMatchPredicate = new FieldCompareValuePredicate(ParameterStringFields.Value, null, ComparisonOperator.Equal, "L001");
    jobCodeValueMatchPredicate.CaseSensitiveCollation = true;
    bucket.PredicateExpression.Add(jobCodeValueMatchPredicate);

// Inner Query Begin
RelationCollection inRelations = new RelationCollection();
inRelations.Add(JobEntity.Relations.ParameterEntityUsingJobFk, "J2", "P2", JoinHint.Inner);
inRelations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk, "P2", "JTP2", JoinHint.Inner);

PredicateExpression inPredicate = new PredicateExpression();
inPredicate.Add(JobTypeParameterFields.SetObjectAlias("JTP2") == JobTypeParameterFields.Name);

inPredicate.Add(JobFields.Id.SetObjectAlias("J2") == JobFields.Id);

SortExpression inSorter = new SortExpression(ParameterFields.Id.SetObjectAlias("P2") | SortOperator.Descending);

FieldCompareSetPredicate fieldCompareSetPredicate = new FieldCompareSetPredicate(
    ParameterFields.Id,
    null,
    ParameterFields.Id.SetObjectAlias("P2"),
    null,
    SetOperator.In,
    inPredicate,
    inRelations,
    null,
    1,
    inSorter);
// Inner Query End

bucket.PredicateExpression.Add(fieldCompareSetPredicate);

DataTable dynamicList = new DataTable();
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchTypedList(fields, dynamicList, bucket, 0, null, true, null);

I've used a TypeFilter for the ParameterString. I've also used the short form for some predicates and for the sort clause in the inner query.

Also in the Inner Query, instead of:

inRelations.Add(JobEntity.Relations.ParameterEntityUsingJobFk, "J2", "P2", JoinHint.Inner);

You can use the opposite relation:

inRelations.Add(ParameterEntity.Relations.JobEntity..., "P2", "J2", JoinHint.Inner);
Posts: 48
Joined: 26-Mar-2007
# Posted on: 29-Nov-2007 14:06:10   

New code still crashes at the same point. I have emailed you a simple DB + project

--Sam

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Nov-2007 15:40:17   

I've got your mail. I'll look into it and get back to you.

(EDIT) Got it. The main problem of the new exception was that you were passing null for the string parameter of the objectAlias string paramter of the FieldCompareSetPredicate CTor. Instead pass "" an empty string.

Also I've made some changes to the code, and below is the working version:

        public static EntityCollection<JobEntity> GetJobsForList(int maxCount, string jobCodeFilter)
        {
            EntityCollection<JobEntity> jobs = new EntityCollection<JobEntity>();
            IRelationPredicateBucket bucket = new RelationPredicateBucket();

            if (jobCodeFilter.Length > 0)
            {
                bucket.Relations.Add(JobEntity.Relations.ParameterEntityUsingJobFk);
                bucket.Relations.Add(ParameterStringEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk);

                FieldCompareValuePredicate jobCodeNameMatchPredicate = new FieldCompareValuePredicate(JobTypeParameterFields.Name, null, ComparisonOperator.Equal, "JobCode");
                jobCodeNameMatchPredicate.CaseSensitiveCollation = true;
                bucket.PredicateExpression.Add(jobCodeNameMatchPredicate);

                FieldCompareValuePredicate jobCodeValueMatchPredicate = new FieldCompareValuePredicate(ParameterStringFields.Value, null, ComparisonOperator.Equal, "L001");
                jobCodeValueMatchPredicate.CaseSensitiveCollation = true;
                bucket.PredicateExpression.Add(jobCodeValueMatchPredicate);

                // Inner Query Begin
                RelationCollection inRelations = new RelationCollection();
                inRelations.Add(JobEntity.Relations.ParameterEntityUsingJobFk, "J2", "P2", JoinHint.Inner);
                inRelations.Add(ParameterEntity.Relations.JobTypeParameterEntityUsingJobTypeParameterFk, "P2", "JTP2", JoinHint.Inner);

                PredicateExpression inPredicate = new PredicateExpression();
                inPredicate.Add(JobTypeParameterFields.Name.SetObjectAlias("JTP2") == JobTypeParameterFields.Name);

                inPredicate.Add(JobFields.Id.SetObjectAlias("J2") == JobFields.Id);

                SortExpression inSorter = new SortExpression(ParameterFields.Id.SetObjectAlias("P2") | SortOperator.Descending);

                FieldCompareSetPredicate fieldCompareSetPredicate = new FieldCompareSetPredicate(
                    ParameterStringFields.Id,
                    null,
                    ParameterFields.Id.SetObjectAlias("P2"),
                    null,
                    SetOperator.In,
                    inPredicate,
                    inRelations,
                    "",                // <---------------------------------------------
                    1,
                    inSorter);
                // Inner Query End

                bucket.PredicateExpression.Add(fieldCompareSetPredicate);
            }


            Context tempContext = new Context();
            tempContext.Add(jobs);
            SortExpression sorter = new SortExpression(JobFields.Id | SortOperator.Descending);

            DataAccessAdapter adapter = new DataAccessAdapter();
            adapter.CommandTimeOut = 120;
            adapter.KeepConnectionOpen = true;
            adapter.ParameterisedPrefetchPathThreshold = 150; //Required to fix LLBLGen bug

            adapter.FetchEntityCollection(jobs, bucket, maxCount, sorter, null);

            int totalMatches = adapter.GetDbCount(new JobEntityFactory().CreateFields(), bucket, null, false);

            return jobs;
        }

I'll mail you back the solution.

Posts: 48
Joined: 26-Mar-2007
# Posted on: 07-Dec-2007 11:26:43   

Thanks! Wonderful support as ever.