This project has moved and is read-only. For the latest updates, please go here.

Number of objects in a table

Sep 6, 2011 at 10:59 AM

IS there an easy way to determine the number of instances in a table?  Rather than read through them all?   And if so, is it efficient? 

I am using Sterling for a WP7 app and would like to limit some of the functionality in a trial mode by stopping items being added once it reaches a certain size.  

- Thanks - Peter

Sep 6, 2011 at 11:46 AM

Just use a LINQ query against the key, i.e. var numRecords = database.Query<MyTable,int>().Count();

Sep 22, 2011 at 10:30 AM
Edited Sep 22, 2011 at 10:32 AM

I have tried the following code But I am getting an invalid cast  - "When casting from a number, the value must be a valid number less than infinity.".   

(A first chance exception of type 'System.InvalidCastException' occurred in Wintellect.Sterling.WindowsPhone.dll)


Any ideas?  Thanks!



 public int CountRecurringEvents()   


  var numRecords = MyDatabase.Query<RecurringEventDB, int>().Count();

 return numRecords;