Filter record by Month and Year - Linq

Mar 04, 2019 BY SOL

This shows how to comparing the date part of datetime in a LINQ query. In a LINQ query it is easy to perform datetime comparisons, to compare only date not time part of a datetime field of data entity.


_events = (from a in _eventRegistory.Table
                           where (a.fdate.Year == Year || a.tdate.Year == Year)
                           select new Events
                               {
                                   eventID = a.eventID,
                                   fdate = a.fdate,
                                   ftime = a.ftime,
                                   tdate = a.tdate,
                                   ttime = a.ttime,
                                   title = a.title,
                                   details = a.details,
                                   photo = a.photo,
                                   url = EventImageUrl
                               }).ToList<Events>();

Can get and compare by date part only from Date-time value.


user.present = (_Usr.Table.Where(a => a.UserId == user.Id
                    && DbFunctions.TruncateTime(a.InDatetime) == Today)).Count();

Related