一种实现方法是这样的:
One way to achieve it would be like this:
val now = DateTime.now val today = now.toLocalDate val tomorrow = today.plusDays(1) val startOfToday = today.toDateTimeAtStartOfDay(now.getZone) val startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(now.getZone) val todayLogItems = logItems.filter(logItem => logItem.MyDateTime >= startOfToday && logItem.MyDateTime < startOfTomorrow ).list有什么方法可以更简洁地编写查询?符合以下条件的东西:
Is there any way to write the query in a more concise way? Something on the lines of:
logItems.filter(_.MyDateTime.toDate == DateTime.now.toDate).list我之所以这样问,是因为在LINQ to NHibernate中是可以实现的(使用nhibernate仅通过日期部分比较来按日期获取记录).
I'm asking this because in LINQ to NHibernate that is achievable (Fetching records by date with only day part comparison using nhibernate).
推荐答案除非Slick joda映射器添加了对比较的支持,否则除非您自己添加比较,否则您将不走运.为了给它一个机会,这些可能是有用的指针: * slick.typesafe/doc/2.0.0/userdefined. html * slick.typesafe/doc /2.0.0/api/#scala.slick.lifted.ExtensionMethods * github/slick/slick/blob/2.0.0/src/main/scala/scala/slick/lifted/ExtensionMethods.scala
Unless the Slick joda mapper adds support for comparisons you are out of luck unless you add it yourself. For giving it a shot these may be helpful pointers: * slick.typesafe/doc/2.0.0/userdefined.html * slick.typesafe/doc/2.0.0/api/#scala.slick.lifted.ExtensionMethods * github/slick/slick/blob/2.0.0/src/main/scala/scala/slick/lifted/ExtensionMethods.scala
我创建了一个票证,以便在某些时候在Slick中对其进行研究: github. com/slick/slick/issues/627
I create a ticket to look into it in Slick at some point: github/slick/slick/issues/627
更多推荐
光滑:筛选所有具有joda DateTime日期等于今天的记录
发布评论