Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Best way to write DoesRowMatchingCriteriaExist query
 

Pages: 1
LLBLGen Pro Runtime Framework
Best way to write DoesRowMatchingCriteriaExist query
Page:1/1 

  Print all messages in this thread  
Poster Message
saggett
User



Location:
Manchester, UK
Joined on:
12-Nov-2007 15:44:46
Posted:
50 posts
# Posted on: 20-Aug-2008 17:25:40.  
I'm using Adapter on .Net 3.5, June 6th Release.

I'm trying to figure out the most efficient way to get a bool result stating whether or not there is a row in a db table matching the criteria expressed by a RelationPredicateBucket. At the moment I've got:


Code:
public bool EntityMatchingCriteriaExists(IEntityFactory2 factory, IRelationPredicateBucket criteria)
        {
            var collection = new EntityCollection(factory);
            var adapter = CreateAdapter();
            return adapter.GetDbCount(collection, criteria) > 0;
        }


But this is sub-optimal as I don't need the count, I just need to find out whether there's anything matching that criteria in the table.

Any ideas?

Thanks, Stephen
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8099 posts
# Posted on: 20-Aug-2008 21:31:31.  
Hi Stephen,

I think EXISTS if at lest 36% more efficient than COUNT(*) in this case:
Code:
public bool EntityMatchingCriteriaExists(IEntityFactory2 factory, IRelationPredicateBucket criteria)
{
    var collection = new EntityCollection(factory);
    var adapter = CreateAdapter();

    IRelationPredicateBucket newFilter = new RelationPredicateBucket();
    FieldCompareSetPredicate existsPredicate = new FieldCompareSetPredicate(null, null,
        factory.CreateFields()[0], null, SetOperator.Exist,
        criteria.PredicateExpression, criteria.Relations, "", 1, null, false, null);

    newFilter.PredicateExpression.Add(existsPredicate);
    
    adapter.FetchEntityCollection(collection, newFilter, 1);

    return collection.Count > 0;
}


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.