I am using the following
var validLogin = from P in this.DataContext.Persons
where P.UserName.Equals(login) && P.Password.Equals(password)
select new
{
P.FirstName,
P.LastName,
P.EmailAddress
};
In this now i want to know, is there any result returned by this query? How to do this.
Don’t use
Count()– useAny()unless you actually care about the count.You can actually simplify this a lot, because you don’t use the rest of the results either:
The nice thing about
Any()is that whatever’s processing the query can stop as soon as it’s found any matching results – it doesn’t need to keep looking for other potential matches. (Count()will work of course, it’s just not as efficient, mostly because the operator itself isn’t describing what you really care about as accurately.)