ef core一直报Sequence contains more than one matching element

Posted 棉晗榜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ef core一直报Sequence contains more than one matching element相关的知识,希望对你有一定的参考价值。

框架版本:.NET6
EF Core版本 5.0
System.InvalidOperationException: Sequence contains more than one matching element

System.InvalidOperationException: Sequence contains more than one matching element
  at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
  at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
  at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
  at Microsoft.EntityFrameworkCore.Query.QueryableMethods..cctor()
  --- End of inner exception stack trace ---
  at Microsoft.EntityFrameworkCore.Query.QueryableMethods.get_FirstOrDefaultWithPredicate()
  at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken)
  at Lmn.Express.Application.Services.Auth.AuthService.LoginAsync(CredentialDto input) in 

异常情况:ToList()的所有方法都异常了。

解决:升级EF Core为6.0版本解决

参考文档:
https://github.com/dotnet/efcore/issues/26635

以上是关于ef core一直报Sequence contains more than one matching element的主要内容,如果未能解决你的问题,请参考以下文章

.Net EF Core千万级数据实践

EF Core中通过Fluent API配置一对一关系

EF Core中通过Fluent API配置一对一关系

EF Core中通过Fluent API配置一对一关系

.NET Core Beta驱动已出,动手写EF Core Oracle

EF Core:一统SQL和NoSQL数据库