有关Date的LINQ查询问题

时间:2012-08-14 12:26:47

标签: c# linq

我想列出CloseDate大于DateTime.Now的所有记录。

我已经为此编写了一个查询,但它没有获取CloseDate大于DateTime.Now的记录。
请参阅下面的查询

 var query = (from x in objEntity.VacancyMsts
                     join o in objEntity.OrganizationMst on 
                     x.OrganizationID equals o.OrganizationId into vacorg
                     from o in vacorg.DefaultIfEmpty()
                     where x.Status == true && x.CloseDate >= DateTime.Now
                     select new VacancyMstDTO
                     {});

我的查询有问题吗?

1 个答案:

答案 0 :(得分:0)

如果你有FK关系,你不需要加入这里

var query = from x in objEntity.VacancyMsts
            where x.Status && x.CloseDate >= DateTime.Now
            select new VacancyMstDTO
            {
                OrganizationName = x.OrganizationMst.Name,
                ...
            };

但是我想知道如果你真的想让CloseDate领先于今天,通常会在过去发生关闭日期,不是吗?

并且小心还有时区。我倾向于始终使用DateTime.UtcNow插入/更新数据库,并在阅读时应用用户时区...

相关问题