[英]Checking if a record exist returns "Sequence contains more than one matching element." for Net5 with Entity Framework 5
I have an .Net5 solution using Entity Framework 5.0.0.我有一个使用 Entity Framework 5.0.0 的 .Net5 解决方案。 Im able to save data to the Backend SQL DB and all is well.
我能够将数据保存到后端 SQL 数据库,一切都很好。 But when I try to check is a record exist using the statement below im getting an error " Sequence contains more than one matching element. "
但是当我尝试使用下面的语句检查是否存在记录时,我得到一个错误“序列包含多个匹配元素。 ”
var status = await dbContext.Item.AnyAsync(x => x.Name == "Bread")
I'm not sure what's causing this.我不确定是什么原因造成的。 Any help appreciated
任何帮助表示赞赏
Im using the following packages我使用以下软件包
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0">
This is not an error that should come back from AnyAsync
.这不是应该从
AnyAsync
返回的错误。 I suspect there is something in the structure of your items (eg via a foreign key) that is generating the error.我怀疑您的项目结构中有某些东西(例如通过外键)会产生错误。 Use
ToTraceString()
to find out the underlying SQL query.使用
ToTraceString()
找出底层 SQL 查询。
I solved it by updating all my EntityFramework related packages to我通过将所有与 EntityFramework 相关的包更新为
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.17">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.