title: How to update a list of multiple records same as normal SQL Update query using entity framework core?
body: <p>Normally in SQL we can write this query <code>UPDATE users SET isAdult = 1 WHERE age &gt;18</code></p>
  
  <p>I want to apply some edit to all rows that satisfy some condition in entity framework core.</p>
  
  <p>I wrote this code and I got an error</p>
  
  <pre><code>List&lt;User&gt; usersList = _context.Users.Where(u =&gt; u.age &gt;18).ToList();
  usersList.ForEach(a =&gt;
                  {
                      a.isAdult = 1;
                  });
  _context.Entry(usersList).State = EntityState.Modified;
  _context.SaveChanges();
  </code></pre>
  
  <p>The error is</p>
  
  <blockquote>
    <p>System.InvalidOperationException: The entity type 'List' was not
    found. Ensure that the entity type has been added to the model.    at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.GetOrCreateEntry(Object
    entity)    at
    Microsoft.EntityFrameworkCore.DbContext.EntryWithoutDetectChanges[TEntity](TEntity
    entity)    at
    Microsoft.EntityFrameworkCore.DbContext.Entry[TEntity](TEntity entity)</p>
  </blockquote>
  
  <p>I made this update but I want to know if this is the best way.</p>
  
  <pre><code>List&lt;Users&gt; usersList = _context.Users.Where(u =&gt; u.age &gt;18).ToList();
  usersList.ForEach(a =&gt;
                  {
                      a.isAdult = 1;
                      _context.Entry(a).State = EntityState.Modified;
                       _context.SaveChanges();
                  });
  </code></pre>