skip to Main Content

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


  1. Chosen as BEST ANSWER

    I solved it by updating all my EntityFramework related packages to

    <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">
    

  2. 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. Use ToTraceString() to find out the underlying SQL query.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search