Question

New to Linq to Entity, trying to get all records received within the last six months. I have spent the last several hours trying to get this to work. Any assistance would be greatly appreciated. When I call the 'limit' variable it is being assigned the date 01/01/0001. Any assistance would be appreciated. It works if I comment out the 'where' clause; however, I need it to be sorted by only the last six months.

Thanks in advance.

 JobSeekersEntities context = new JobSeekersEntities();

 var limit = DateTime.Today.AddMonths(-6);

        var query = from c in context.Applications
                    where c.received > limit
                    orderby c.received descending
                    select new { c.firstName, c.middleName, c.lastName, c.street, c.city, c.state, c.zip, c.position };

        var results = query.Take(25).ToList();

        applicationDataGrid.DataContext = results;
Was it helpful?

Solution

If you stop the debugger at the line "var limit = " you will get that value. You need to press F10 to step over that code then look at value, it will be correct. Have to let that line run so that limit gets assigned. Var in this case is DateTime, which is a value type so it has a default value. I could see this being misleading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top