Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have web form .in which i have button to delete all records against one date.there are two fields in the form,one drop down list where all sector are given,and is a date.when user select a sector and put a date in the field,and click on delete button then all record will be deleted.c# code is as follow,i want linq statement in which i can use where clause.
C#
protected void Clear_Roaster(object sender, EventArgs e)
      {
          int sectorId = SafeConvert.ToInt32(ddlsectorRoaster.SelectedValue);
          DateTime dt = SafeConvert.ToDateTime(txtDate.Text);

         int deleteRecord = _service.GetAllBeatStatus().Where(x => x.Date == dt).Count();
         if (deleteRecord != null)
         {
             _service.DeleteBeatStatus(deleteRecord);
         }
         else
         {
             MsgLitteral.ShowNotificationInline("No Record Found!.", true);

         }

just base on date leave sector drop down
Posted
Updated 13-Jan-15 19:25pm
v2
Comments
DamithSL 14-Jan-15 0:48am    
you need both date and sector id in where condition? can you update the question with the code which you have tried so far?
Sajid227 14-Jan-15 1:23am    
i have update my question now plz helpm me now

C#
var service = from a in _service
               where a.SectorID == sectorId 
               select a;
_service.RemoveAll(service);
_service.SubmitChanges();
 
Share this answer
 
Comments
Sajid227 14-Jan-15 1:22am    
i have update my question plz help me now
DamithSL 14-Jan-15 1:24am    
delete this, you have post this code as a solution to your question.
there is a improve question link below the question, click on that and update the question.
Sajid227 14-Jan-15 1:33am    
i use improve qustion link to improve details
if you need to include Date in your where condition then send date as parameter DeleteEmployeeStatus method and update the method signature
C#
_service.DeleteEmployeeStatus(sectorId, dt);

then you need both conditions like where a.SectorID == sectorId and a.ToDate = dt but when you are working with DateTime value with Database Date/DateTime in entity framework you need to be careful with the code. Read below article for few ways you can try
LINQ query to compare only date part of DateTime[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900