Sequence contains no elements when using count on LINQ Query
问题 IEnumerable<EntityReference> children = ( from c in OrgContext.CreateQuery<Account>() where c.ParentAccountId != null && c.ParentAccountId.Id.Equals(parentGuid) select c.ToEntityReference()).ToList(); return children.Count() > 0 ? null : new List<EntityReference>(); Throws a "Sequence contains no elements" error. How can I reliably check if the sequence is empty before trying to count the elements? (I'd expect Count to simply return 0) 回答1: This error for me was caused by visual studio using