Right off the bat I’m very new to LINQ to SQL (and C# in general) and haven’t successfully implemented .Any() before. I’m using .Net 4.0 with Visual Studio 2010.
I’ve added a new LINQ to SQL data set to my project and I’m trying to do the following:
var db = new HealthIndicatorsDataContext();
var d = DateTime.Today;
if(db.HealthIndicators.FirstOrDefault(h => h.LogDate == d).Any())
// do something
Unfortunately I’m receiving Cannot Resolve Sysmbol 'Any' and .Any() is highlighted in red. I’ve read that I needed to reference System.Core.dll in my project, I’ve added this but I’m still having no luck. What am I missing?
FirstOrDefault()returns a single item and not anIQueryableorIEnumerable–Any()is only defined on those. What you probably meant to write is:or (better):