简体   繁体   中英

does not contain a definiton for where for linq

I want to query from Users table with linq query. I am getting an error on this line on "Users.Where"; var KisiList = Users.Where(w => w.Userstatus == 1 && w.Isactive == 1).ToList(); Users does not contain a definiton for where. what should I add here?

public List<Users> GetBagliOlduguKisiList()
{

     var KisiList = Users.Where(w => w.Userstatus == 1 && w.Isactive == 1).ToList();
    List< Users> users= new List< Users>();
    
    foreach (var item in KisiList )
    {
        Users par= new Users();
        par. ID= item. ID;
        par. Name= item. Name;
        users.Add(par);
    }

    return users;
}

Probably you have missed using System.Linq; . Also if you are using LINQ, try to do that effectively and retrieve only needed fields.

public List<Users> GetBagliOlduguKisiList()
{
    var users = Users
       .Where(w => w.Userstatus == 1 && w.Isactive == 1)
       .Select(u => new Users
       { 
          ID = u.ID,
          Name = u.Name
       })
       .ToList();

    return users;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM