我正在处理的日期比较存在一些问题,您将在代码中看到这些问题(很高兴知道如何在没有编译错误的情况下执行 DateTime.Now.AddMonth(2)),但我真正感兴趣的是这就是为什么当我遍历我的 foreach 并尝试打印雇主组织名称时,我得到一个空指针异常。以下调试确认雇主实体存在,但为空。我希望加入可以让我访问这个......
csoDBConDataContext db = new csoDBConDataContext();
db.ObjectTrackingEnabled = false;//see above comment
var results = (from job in db.jobs
join employer in db.employers on job.employer_id equals
employer.employer_id
where job.cache_major.Contains("business") &&
job.count_major <= 30 && job.del != true &&
job.joblocation != null &&
DateTime.Now.AddMonth(2).CompareTo(((DateTime)job.postdate)) >= 0 &&
DateTime.Now.CompareTo(((DateTime)job.expiredate)) >= 0 &&
job.status_id != 406
orderby Convert.ToDateTime(job.postdate).DayOfYear
select job
).Take(20);
foreach (var j in results) {
output += j.jobtitle + j.joblocation + j.expiredate + j.postdate +
j.employer.organizationname + Environment.NewLine + Environment.NewLine;
}