I am trying to convert the below mentioned SQL query to LINQ query
Qry = "select Announcement, StartDate, Enddate,Annkey from
Announcements "; Qry = Qry & " where Startdate <= #" & Today & "# "
Qry = Qry & " and Enddate >= #" & Today & "# " Qry = Qry + " order by
StartDate, Enddate";
What I have made so far -
public bool Selectdatafromannouncements()
{
List<Announcement> lstAnnounce = new List<Announcement>(
from l in objVaccinationContext.Announcements
where
l.StartDate.Value < DateTime.Today
&& l.EndDate.Value < DateTime.Today
orderby l.StartDate, l.EndDate
select new (l.Announcement1, l.StartDate, l.EndDate, l.AnnouncementID)
);
return true;
}
Getting an error near select new ( as type expected please help me out i am a beginner with LINQ
You don't need a constructor here, for creating the list. The curly braces are used for creating anonymous objects, so instead of declaring lstAnnounce of
List<Announcement>type, better use the var keyword.So you can have this:
If you need a list of Annoucement objects: