Count() issue with Oracle backend

2 posts, 1 answers
  1. Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 10 Jul 2009 Link to this post

    Hey guys,

    I'm using Oracle as a backend and trying to call Count(), passing in a predicate, but am getting an incorrect result. It basically returns the total number of rows in my table regardless of the query passed in as the predicate. Here some code...

    1 // When trying with parameters passed to the method,  
    2 // I get the TOTAL number of Customers 
    3 var database = Database.Get("ConnectionString"); 
    4 var dataContext = database.GetObjectScope(); 
    5 var records = dataContext.Extent<Customer>().AsQueryable<Customer>(); 
    6 var count = records.Count(c => c.City == city && c.Country == country); 
    8 // When trying with hard-coded values,  
    9 // I still get the TOTAL number of Customers 
    10 var database = Database.Get("ConnectionString"); 
    11 var dataContext = database.GetObjectScope(); 
    12 var records = dataContext.Extent<Customer>().AsQueryable<Customer>(); 
    13 var count = records.Count(c => c.City == "Fairfax" && c.Country == "USA"); 
    16 // When bringing the results in memory (and not using a predicate), Count() returns the 
    17 // correct number of Customers 
    18 var database = Database.Get("ConnectionString"); 
    19 var dataContext = database.GetObjectScope(); 
    20 var records = dataContext.Extent<Customer>().AsQueryable<Customer>(); 
    21 var customers = records.Where(c => c.City == "Fairfax" && c.Country == "USA").ToList<Customer>(); 
    22 var count = customers .Count(); 

    Bringing the data in memory to count total records is not an option because I am dealing with a table of more than 30M records.

    Is there an issue with Count() in general, or with Oracle in particular?

    Thanks, and regards,
    Kevin Babcock
  2. Answer
    Alexander avatar
    727 posts

    Posted 14 Jul 2009 Link to this post

    Hello Kevin,

    This was a bug on our side and has already been fixed. The fix will be available in our next service pack which is coming in few weeks. In the meanwhile you can use a Where statement and then count the results:
    records.Where(c => c.City == city && c.Country == country).Count(); 
    This is also executed on the server and should not slow down the performance.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
Back to Top