문제

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;
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top