本文介绍了光滑的表查询:无法识别值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在这种情况下,谁能告诉我原因

Can anyone tell me why in this case:

Query(Users) foreach {case (userId, userName) =>
    println(userId + ", " + userName) }

Scala可以识别userId,但在这种情况下:

Scala recognizes userId, but in this case:

val l = List[(Int, String)]()

Query(Users) foreach {
   case (userId, userName) =>
     l::(foo(List[(userId, userName)]))
}

不是吗? (例如,在第二种情况下会识别"=>"右侧的userId,但在第一种情况下不会识别)

it doesnt? (as in, the userId on the right of the "=>" is recognized in the second case but not the first)

Users是一个光滑安装的数据库,如下所示:

Users is a slick-mounted database that looks like this:

object Users extends Table[(Int, String)]("Users") {

  def userId          = column[Int]("UserId", O.PrimaryKey, O.AutoInc)
  def userName        = column[String]("UserName")

  def * = userId ~ userName
}

推荐答案

我认为您的意思是:

l::(foo(List((userId, userName))))

将东西放在方括号之间时,您正在尝试键入列表,我假设您实际上是想将userIduserNameTuple添加到列表中.

When you put stuff between the square brackets, you are attempting to type the list and I assume you actually wanted to add the Tuple of userId and userName to a List instead.

如果您只想将所有内容放入该List中,而又不需要该Tuple提取器,则也可以这样编写:

You could also write it like this if all you wanted to do was put it into that List and you did not need that Tuple extractor:

Query(Users) foreach { tup =>
  l::(foo(List(tup)))
}

这篇关于光滑的表查询:无法识别值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:47