开发者

Compare only Date in nHibernate Linq on a DateTime value

I trying to compare two dates (DateTime) in nHibernate linq:

query = qu开发者_如何学Cery.Where(l => (l.datCriacao.Date == dtLote.Date)

but I am getting the error:

NHibernate.QueryException: could not resolve property: datCriacao.Date of: SAGP.Entities.Lote

Anyone knows how I can solve this? Thanks


I solved the problem doing a between with the dates:

DateTime initialDate, finalDate;
initialDate= DateEntity.Date;
finalDate= new DateTime(DateEntity.Year, DateEntity.Month, DateEntity.Day, 23, 59, 59);
query = query.Where(l => (((l.dateEntity>= initialDate) && (l.dateEntity<= finalDate))


This is super old, but I'd add to jaspion's example as:

query = query.Where(l => (l.datCriacao >= dtLote.Date && l.datCriacao < dtLote.Date.AddDays(1))


You can check the condition like this

var nextDay = DateTime.Today.AddDays(1);

query = query.Where(l => (l.datCriacao >= dtLote && l.datCriacao < nextDay);

here you'll get the records on dtLote date as we checking between dtLote and dtLote+1 day (00:00:00) we'll get today's date record only what ever may be the time...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜