*用案例类投影

时间:2015-08-25 11:41:57

标签: scala slick slick-3.0

所以我关注:http://slick.typesafe.com/doc/3.0.2/gettingstarted.html现在我想使用案例类而不是将每个模型定义为元组。

所以我有:

case class Character(id: Long, foreName: String, middleNames: String, lastName: String, age: Int)

//class Characters(tag: Tag) extends Table[(Int, String, String, String, Int)](tag, "characters")
class Characters(tag: Tag) extends Table[Characters](tag, "characters")
{
  def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
  def foreName = column[String]("forename")
  def middleNames = column[String]("middlenames")
  def lastName = column[String]("lastname")
  def age = column[Int]("age")

//  def * = (id, foreName, middleNames, lastName, age)
  def * = (id, foreName, middleNames, lastName, age) <> (Character.tupled, Character.unapply _)
}

但我明白了:

  

MappedProjection类型的表达式[Character,(Long,String,String,   String,Int)]不符合预期类型ProvenShape [Characters]

但为什么呢?它基本上与:http://de.slideshare.net/rebeccagrenier509/slick-learn2幻灯片7相同。即使只是Slick 2,我怎样才能在Slick 3中实现相同的效果?

1 个答案:

答案 0 :(得分:7)

看起来你想要... extends Table[Character],而不是... extends Table[Characters]