Simple SELECT WHERE LINQ List Query

I'm new to LINQ,

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

Is that what I have so far, but am getting an error message?

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();                  
        }
    }
+4
source share
2 answers

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

shorter way

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

For your editing

the return type of the method should be List<Sim>, notList<String>

+16
source

It will work

return db.sims.Where(x=>x.has_been_modified).ToList();
  • The Linq method looks cleaner here.
  • you do not need to check your bool for true
  • s x, select s
  • ToList
+2

All Articles