I can't get the following code with the included implicit working. The variable ls contains a list of tuples like defined in the Tuple2Store implicit. My foreach lamda argument requires the members of the list to be instances of the class Store. So why does the implicit conversion not kick in?
implicit def Tuple2Store(tuple: (Int, Option[Date], Option[String], Option[Date], Option[Boolean], Option[Boolean],
Option[Boolean], Option[Boolean], Option[String])): Store =
{ new Store(tuple._1, tuple._2, tuple._3, tuple._4, tuple._5, tuple._6, tuple._7, tuple._8, tuple._9) }
val entities = TableQuery[StoreTable]
val query = for {
c <- entities if c.costCenterNumber === 60506
} yield (c)
val ls = query.list
ls.foreach((s: Store) => println(s.toString))
Following error message is displayed:
- type mismatch; found : datamodel.Store => Unit required: ((Int, Option[java.sql.Date], Option[String], Option[java.sql.Date], Option[Boolean], Option[Boolean], Option[Boolean], Option[Boolean], Option[String])) => ?
Edit: The following code leaves me with a List of Store instances in the ls variable... this is what I wanted to accomplish, but is there an easier way?
implicit def Tuple2Store(tuple: (Int, Option[Date], Option[String], Option[Date], Option[Boolean], Option[Boolean],
Option[Boolean], Option[Boolean], Option[String])): Store =
{ new Store(tuple._1, tuple._2, tuple._3, tuple._4, tuple._5, tuple._6, tuple._7, tuple._8, tuple._9) }
val entities = TableQuery[StoreTable]
val query = for {
c <- entities if c.costCenterNumber === 60506
} yield (c)
val ls = query.list.map { Tuple2Store }
ls
asList[Store]
and you should be ready to go, e.g.val ls: List[Store] = query.list
. - fotNeltonyield
and be done with it? - wheaties