Scala value delete不是slick.lifted.Query[T,T#TableElementType,Seq]的成员

Scala value delete不是slick.lifted.Query[T,T#TableElementType,Seq]的成员,scala,playframework,slick,play-slick,Scala,Playframework,Slick,Play Slick,我现在正在玩Play和Play slick。下面的代码给了我一个错误 class GenericRepository(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] { import driver.api._ implicit val localDateTimeColumnType = MappedColumnType.base[

我现在正在玩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)
  }
}
我已经在谷歌上搜索了很多,但没有一个解决方案对我有效。例如,我尝试将“import driver.api.”替换为“import slick.driver.H2Driver.api.”,但运气不好


我将Scala 2.11.7与play slick 2.0.2和play 2.5一起使用。

编辑:从粘贴的代码中,我现在看到了您的问题

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


除此之外,它看起来还不错。

此外,您可能会认为从
crudepository
方法返回
Future
是否有意义。这种方法不允许您在事务中执行操作。嘿,谢谢您的回答!不幸的是,这导致了另一个错误:显然,Scala无法看到两个类的驱动程序导入是相同的。对我来说,db.run总是返回一个未来,顺便说一句。看看我更新的答案-它会让你的代码编译。这是什么版本的Slick?我在slick 3.1.0中没有
slick.relational.RelationalProfile.API.Table
(但问题相同)。找到它:.profile.API.Table
value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]
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)
  }
val crud = new CrudRepository[Redirect,RedirectsTable](Redirects)