GetDbCount exception

Posts   
 
    
kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 24-Nov-2010 03:30:53   

I've looked at the existing threads trying to find the problem, but it seems to be a lot related to GetDbCount, so I'm sorry if it is dublicate.

The problem is that when getting data for the grid I need to get a total record count to calculate number of pages and show user amount of records.

I'm trying to use Adapter.GetDbCount method accepting the fields, relations, group by and I want the query to be as effective as it is possible, so one of the things I'm trying to do is basically remove the fields so that it would do something like select count() from (select id from ...) instead of select count() from (select id, all the fields ..... from ...) May be it is not worth doing it, but that's another question. In my case it is throwing an error:

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException : An exception was caught during the execution of a retrieval query: The multi-part identifier "net.metType.IsSystem" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. ----> System.Data.SqlClient.SqlException : The multi-part identifier "net.metType.IsSystem" could not be bound. at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.ExecuteScalar() in RetrievalQuery.cs: line 155 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteScalarQuery(IRetrievalQuery queryToExecute) in DataAccessAdapterBase.cs: line 466 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetDbCount(IEntityFields2 fields, IRelationPredicateBucket filter, IGroupByCollection groupByClause, Boolean allowDuplicates) in DataAccessAdapterBase.cs: line 432

when I'm doing this:


            using (var adapter = ...)
            {
                var fields = new ResultsetFields(1);
                fields.DefineField(ObjectFields.Id, 0);

                var bucket = new RelationPredicateBucket(ObjectFields.IsSystem == 0);
                var count = adapter.GetDbCount(fields, bucket, null, true);
                Assert.That(count, Is.EqualTo(317));
            }

ObjectEntity is inherited from TypeEntity and field isSystem is stored in TypeEntity table. I use TargetPerEntity inheritance Adapter templates, latest version of llblgen 2.6.10.930.

Let me know if you need anything else.

Anton

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Nov-2010 04:12:28   

Hi Anton,

Please add this to your code:

var bucket = new RelationPredicateBucket(ObjectFields.IsSystem == 0);
bucket.Relations.Add(ObjectFields.Relations.TheRelationToTheParent);

You should do that in DynamicList fetches.

David Elizondo | LLBLGen Support Team
kievBug
User
Posts: 105
Joined: 09-Jan-2009
# Posted on: 24-Nov-2010 04:16:10   

Well, it probably would work in this case, but this case is just a simlification of more general case which is:


            int recordCount = Adapter.GetDbCount(definition.Fields, definition.Relations, definition.GroupBy,
                                                 definition.AllowDuplicates ?? true);
            var resultData = new DataTable();
            Adapter.FetchTypedList(definition.Fields, resultData, definition.Relations,
                                   definition.MaxNumberOfItemsToReturn ?? 0, definition.SortExpression,
                                   definition.AllowDuplicates ?? true, definition.GroupBy,
                                   definition.PageNumber ?? 0,
                                   definition.PageSize ?? 0);
            return new DataResult
                       {
                           Data = resultData.DefaultView,
                           TotalRecordCount = recordCount,
                       };

This code works, but I want to do something like this:


            var countFields = new ResultsetFields(1);
            countFields.DefineField(definition.Fields[0], 0);

            int recordCount = Adapter.GetDbCount(countFields, definition.Relations, definition.GroupBy,
                                                 definition.AllowDuplicates ?? true);
            ....

Is it possible at all?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-Nov-2010 08:34:41   

You have to link to the parent table, which holds the field you are filtering on.