ahmed ghani
ahmed ghani

Reputation: 67

Lambda expression Where clause

Linq convert into SQL query get value where clause context.purposes.tolist (id = 4000 into 4050) how it is?

public ActionResult Index()
{
        PurposeModel model = new PurposeModel();

        using (DAL.db_Hajj_UmrahEntities context = new DAL.db_Hajj_UmrahEntities())
        {
            List<DAL.Purpose> purposelist = context.Purposes.ToList();
            model.PurposeList = purposelist.Select(x => new SelectListItem()
                {
                    Text =x.PurPose1,
                    Value=x.Id.ToString()
                });
        }

        return View(model);
}

Upvotes: 2

Views: 747

Answers (2)

reza.cse08
reza.cse08

Reputation: 6178

model.PurposeList = purposelist.Where(y => y.ID >= 4000 && y.ID <= 4050)
                               .Select(x => new SelectListItem()
                               {
                                 Text =x.PurPose1,
                                 Value=x.Id.ToString()
                               })
                               .ToList();

Upvotes: 0

Sujit.Warrier
Sujit.Warrier

Reputation: 2869

I think this is what you are looking for

     context.Purposes.where(s=>s.id>=4000 && s.id<=4050).ToList();

Upvotes: 2

Related Questions