5

I am new to LINQ,

I want to generate a list of objects from my dbcontext where a certain field is set to true.

This is what I have so far, but I am getting an error about a select?

using (var db = new dbContext())
{
    return (from s in db.sims.Where(x=>x.has_been_modified == true) select x).ToList();               
}

EDIT:

    //Returns a list of entries which where marked as edited in the sim managment database
    private List<String> GetUpdatedEntries()
    {
        using (var db = new dbContext())
        {
            return db.sims.Where(x => x.has_been_modified).ToList();                  
        }
    }
Zapnologica
  • 20,003
  • 39
  • 136
  • 229

2 Answers2

16

select s, not x and this will work. (because you do from s)

shorter way

return db.sims.Where(x => x.has_been_modified).ToList();

For your Edit

the method return type should be a List<Sim>, not a List<String>

Raphaël Althaus
  • 57,325
  • 6
  • 81
  • 109
2

This will work

return db.sims.Where(x=>x.has_been_modified).ToList();
  1. method Linq looks cleaner here
  2. you don't need to check your bool against true
  3. in your previous answer you used s as context and selected x, changing to select s should work also
  4. Consider using lazy loading and don't add ToList at the end of every query
Kamil Budziewski
  • 21,193
  • 12
  • 77
  • 95