值删除不是 slick.lifted.Query[T,T#TableElementType,Seq] 的成员

value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]

我目前正在玩 Play 和 play-slick。下面的代码给我一个错误

class GenericRepository(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
  import driver.api._

  implicit val localDateTimeColumnType = MappedColumnType.base[LocalDateTime, Timestamp](
    d => Timestamp.from(d.toInstant(ZoneOffset.ofHours(0))),
    d => d.toLocalDateTime
  )

  protected trait GenericTable {
    this: Table[_] =>
    def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
    def createdAt = column[LocalDateTime]("created_at")
    def updatedAt = column[LocalDateTime]("updated_at")
  }

  protected class CrudRepository[T <: AbstractTable[_] with GenericRepository#GenericTable](private val tableQuery: TableQuery[T]) {
    def all = db.run(tableQuery.to[List].result)
    def create(obj: T#TableElementType) = db.run(tableQuery returning tableQuery.map(_.id) += obj)
    def delete(id: Long) = db.run(tableQuery.filter(_.id === id).delete)
  }
}

错误:

value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]

我已经在谷歌上搜索了很多,但没有适合我的解决方案。例如,我尝试用 'import slick.driver.H2Driver.api.' 替换 'import driver.api.' 但没有任何运气。

我正在使用带有 play-slick 2.0.2 和 Play 2.5 的 Scala 2.11.7。

编辑:根据您粘贴的代码,我现在看到了您的问题。

只需将您的定义更改为(我只更改了类型参数):

protected class CrudRepository[E, T <: Table[E] with GenericRepository#GenericTable](private val tableQuery: TableQuery[T]) {
    def all = db.run(tableQuery.to[List].result)
    def create(obj: T#TableElementType) = db.run(tableQuery returning tableQuery.map(_.id) += obj)
    def delete(id: Long) = db.run(tableQuery.filter(_.id === id).delete)
  }

其中 Tableslick.relational.RelationalProfile.API.Table

然后按以下方式实例化您的 CrudRepository

val crud = new CrudRepository[Redirect,RedirectsTable](Redirects)

除了它看起来不错。