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

where not found.

Apr 25, 2011 at 2:56 PM


what happen where can't found any ltems ?, 


'taskhost.exe' (Managed): Loaded 'System.SR.dll'
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll

this is what i got, when where can't found any item. what method should i use to prevent this ?


Apr 25, 2011 at 3:21 PM

Need more details. Not sure what you're asking.

Apr 25, 2011 at 3:58 PM

sorry, this is the scenario. 

i'm looking for category named "tiger", using where syntax. and where cannot find category named tiger. and the application will go crash with error code as above.

my query is,

  catname = "tiger"

 categories = SterlingService.Current.Database.Query<Category, int>()
                    .Where(delegate(TableKey<Category, int> key) { return key.LazyValue.Value.categoryName == catname; })
                    .First<TableKey<Category, int>>()


and there are no error, if i have category named "tiger".

I hope you got what i mean. thanks

Apr 25, 2011 at 4:00 PM

You are demanding that the query return a value, so it will crash if there is not one. If you want to allow for not having a value, you'll need FirstOrDefault, not First.

Apr 25, 2011 at 4:13 PM
Edited Apr 25, 2011 at 5:06 PM

hahaha, sorry jeremy. 

i just need to google "firstordefault" first, and learn from that.