GetDBCount with RelationCollection question

Posts   
 
    
Liero
User
Posts: 40
Joined: 18-Sep-2009
# Posted on: 14-Apr-2010 11:58:23   

I have TransportChain and Transport tables, where Transport.IdTransportChain is fk to TransportChain.IdTransportChain


      var tc = new TransportChainCollection();
      var predicate = TransportFields.CodeSeason == 10;
      var relation = new RelationCollection(TransportEntity.Relations.TransportChainEntityUsingIdTransportChain);
      tc.GetMulti(predicate, relation);
      int count = tc.Count;
      int dbCount = tc.GetDbCount(predicate, relation);

count and dbCount are not the same, dbCount is much bigger. Why?

defining relations as

var relation = new RelationCollection(Ares.LLBL.EntityClasses.TransportChainEntity.Relations.TransportEntityUsingIdTransportChain);

results to the same counts as in previous code. value of count is the one I need, dbCound in invalid in this case.

I need to get count of elements, that should be exactly the same as if i called GetMulti. I need this to implement pager.

using llbl v2.6 / SelfServicing

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 14-Apr-2010 15:08:26   

Code:

 var tc = new TransportChainCollection();
 var predicate = TransportFields.CodeSeason == 10;
 var relation = new RelationCollection(TransportEntity.Relations.TransportChainEntityUsingIdTransportChain);
 tc.GetMulti(predicate, relation);
 int count = tc.Count;
 int dbCount = tc.GetDbCount(predicate, relation); 

count and dbCount are not the same, dbCount is much bigger. Why?

Most probably because the EntityCollection discard duplicates. But the GetDBCount() counts the results of the join.

Anyway this can be debugged by examinig the generated SQL queries in both cases.

Liero
User
Posts: 40
Joined: 18-Sep-2009
# Posted on: 14-Apr-2010 23:48:27   

Yes I think so, but it is a bug, isn't it? I can post sql query tomorrow.

Have you any idea how fix this? confused

I don't know what will be in RelationCollection at design time.

I could use GetMulti on collection with only PK included in select query, but it's bad, very bad practice.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 15-Apr-2010 10:01:25   

IT's not a bug as far as I see it. Just check the generated SQL to see the difference.

Liero
User
Posts: 40
Joined: 18-Sep-2009
# Posted on: 15-Apr-2010 14:53:42   

The problem was that there were a text field in my TransportChainTable. Text is not comparable type in Sql Server 2005 so db DISCTINCT could not be used in generated query.

I suppose that GetMulti removed duplicates on application side.

there was similar thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2343&HighLight=1

the solution at the end works fine for me.