C# 如何在WHERE子句(LINQ)中使用DateTime?
如何添加日期是where子句。我正在使用以下代码C# 如何在WHERE子句(LINQ)中使用DateTime?,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,如何添加日期是where子句。我正在使用以下代码 var opportunites = from opp in this.DataContext.Opportunities join org in this.DataContext.Organizations on opp.OrganizationID equals org.OrgnizationID
var opportunites = from opp in this.DataContext.Opportunities
join org in this.DataContext.Organizations on opp.OrganizationID
equals org.OrgnizationID
select new
{
org.CreatedDate,
org.OrganizationName
};
if (createdDate != string.Empty)
opportunites = opportunites.Where(opp =>
opp.CreatedDate == Convert.ToDateTime(createdDate));
但使用此代码,我不会返回任何结果。我认为错误在于==运算符
我想我应该有这样的代码
"where createdDate between" + createdDate + "00:00:00" + and createdDate + "23:59:59"
如何在LINQ中归档这件事
有什么建议吗 您可以只提取DateTime的“日期”部分,如下所示:
opp.CreatedDate.Date == Convert.ToDateTime(createdDate).Date
您可以向标准添加新日期,只需添加86399秒:
DateTime dtFechaIni = Convert.ToDateTime(filter[0]);
DateTime dtFechaEnd = Convert.ToDateTime(filter[0]).AddSeconds(86399);
var getInfo = from gI in infEnt.tb_FileManagement_RegistrosArchivo
where gI.tb_FileManagement_Archivo.FechaArchivo > dtFechaIni &&
gI.tb_FileManagement_Archivo.FechaArchivo < dtFechaEnd
select gI;
DateTime dtFechaIni=Convert.ToDateTime(过滤器[0]);
DateTime dtFechaEnd=Convert.ToDateTime(过滤器[0]).AddSeconds(86399);
var getInfo=来自infEnt.tb\u FileManagement\u registorArchivo中的gI
其中gI.tb_FileManagement_Archivo.FechaArchivo>dtFechaIni&&
gI.tb\u文件管理\u Archivo.FechaArchivo