I have an .Net5 solution using Entity Framework 5.0.0. Im able to save data to the Backend SQL DB and all is well. 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">
2
Answers
I solved it by updating all my EntityFramework related packages to
This is not an error that should come back from
AnyAsync
. I suspect there is something in the structure of your items (e.g. via a foreign key) that is generating the error. UseToTraceString()
to find out the underlying SQL query.