Is there a better way to check if a LINQ projection query returns results:
IList<T> TList = db.Ts.Where(x => x.TId == 1).ToList(); // More canonical way for this?
if (TitleList.Count > 0)
{
// Result returned non-zero list!
string s = TList.Name;
}
You can use
Any(), or perhaps more appropriately to your example,SingleOrDefault(). Note that if you are expecting more than one result and plan to use all of them, then it doesn’t really save anything to useAny()instead of converting to a List and checking the length. If you don’t plan to use all the results or you’re building a larger query that might change how the query is performed then it can be a reasonable alternative.or