This is a migrated thread and some comments may be shown as answers.

Count() issue with Oracle backend

1 Answer 87 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin Babcock
Top achievements
Rank 1
Kevin Babcock asked on 11 Jul 2009, 01:43 AM
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...

// When trying with parameters passed to the method,  
// I get the TOTAL number of Customers 
var database = Database.Get("ConnectionString"); 
var dataContext = database.GetObjectScope(); 
var records = dataContext.Extent<Customer>().AsQueryable<Customer>(); 
var count = records.Count(c => c.City == city && c.Country == country); 
 
// When trying with hard-coded values,  
// I still get the TOTAL number of Customers 
var database = Database.Get("ConnectionString"); 
var dataContext = database.GetObjectScope(); 
var records = dataContext.Extent<Customer>().AsQueryable<Customer>(); 
var count = records.Count(c => c.City == "Fairfax" && c.Country == "USA"); 
 
 
// When bringing the results in memory (and not using a predicate), Count() returns the 
// correct number of Customers 
var database = Database.Get("ConnectionString"); 
var dataContext = database.GetObjectScope(); 
var records = dataContext.Extent<Customer>().AsQueryable<Customer>(); 
var customers = records.Where(c => c.City == "Fairfax" && c.Country == "USA").ToList<Customer>(); 
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 14 Jul 2009, 10:33 AM
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,
Alexander
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.
Tags
LINQ (LINQ specific questions)
Asked by
Kevin Babcock
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or