Check if record exists in database

Mar 1, 2011 at 1:56 PM

Hey all,

We've recently decided to use the Sterling database in our project. It works pretty great and we're pretty happy with the results. However there is one problem that we can't seem to figure out. Our architecture requires us to Delete a record from the database and then later check if the record still exists. However when I try and read a record with the Load command, so for example:


I get a weird exception back if the record doesn't exist:

"There was an issue accessing isolated storage: Operation not permitted on IsolatedStorageFileStream.. Check the inner exception for details."

Inner exception: "Operation not permitted on IsolatedStorageFileStream."

When the record does exist it works fine. So I don't think we made any mistakes implementing Sterling. Is there any way to check if the record exists? Like a specialised method? Or a way to make the Load return a null value if it doesnt exist? Catching the exception would be really ugly and we'd rather solve it properly.

Thanks for your time,


Mar 3, 2011 at 3:54 PM

I have not run into that before - are you able to duplicate in a test or share some code for me to troubleshoot?

You should be able to load a value that doesn't exist, as Sterling will simply return null.

If you want to check for the existence of a record, use this - basically query the keys for the match and the condition is true if any exist:

if (_databaseInstance.Query<EntityType,int>().Where(i=>i.Id==MyId).Any())

Let me know if that helps or if you continue to experience problems.

Mar 3, 2011 at 4:17 PM

Dear jeremy,

You are correct. We found out earlier that the problem was that we did not do a .Flush() of the database at the right time and thus the index still had the deleted rootentity after we restarted the application. That is why it threw an exception. So basically if the index is corrupt and still has the ID of a record and you try and read that record you get an exception. It's working correctly now. Thanks for your time.