这是由于查询的结果中包含多个数据,解决方法可以改成FirstOrDefault()
Getting an error "Sequence contains more than one element" getting array of ID fields in many to many relationship in Entity framework getting error "cannot Implicitly convert type int? to bool" Getting error LINQ to Entities does not recognize the method 'Int64 ToInt64(System.String)' method ...
Security Insights Additional navigation options New issue Closed carlreinkeopened this issueMay 13, 2018· 8 comments Contributor carlreinkecommentedMay 13, 2018• edited The query compiler throws an exception. System.InvalidOperationException: Sequence contains more than one element at System.Linq.Enume...
An exception occurred while invoking executor 'executor://mstestadapter/v2': Sequence contains more than one element Stack trace: Server stack trace: at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) at Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities.ManagedNameHelper.Fi...
System.InvalidOperationException: Sequence contains more than one matching element в System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) в System.Data.Entity.ModelConfiguration.Edm.EdmEntityTypeExtensions.GetNavigationProperty(EdmEntityType entityType, PropertyInfo propert...
Sequence contains more than one matching element at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) at SqlSugar.ExpressionContext.GetDbColumnName(String entityName, String propertyName) at SqlSugar.MemberExpr...
System.InvalidOperationException: Sequence contains more than one matching element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) at SqlSugar.UpdateableProvider`1.Init() at SqlSugar.SqlSugarProvider.CreateUpdateable[T](T[] UpdateObjs)...
When to use .First and when to use .FirstOrDefault with LINQ? I would useFirst()when I know or expect the sequence to have at least one element. In other words, when it is an exceptional occurrence that the sequence is empty.
When to use .First and when to use .FirstOrDefault with LINQ? I would useFirst()when I know or expect the sequence to have at least one element. In other words, when it is an exceptional occurrence that the sequence is empty.
So sometimes you will get these strange errors or exceptions when usingLinq Sequence contains no matching element For example if you use 1 varresult=myEnumerableCollection.First(x=>x.Name==person.Name); This will throw InvalidOperationException with Sequence contains no matching element. ...