Q:

How to update the sql server's identity column using play2.6 slick3?

I got the following error when i try to run the sbt scala project using sql server,
[SQLServerException: Cannot update identity column 'ID'.]
I am using Play 2.6,Scala 2.12, Slick 3
my update function is,
def update(id: Long): Action[AnyContent] = Action.async { implicit request =>
    topicForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.editForm(id, formWithErrors))),
      topic => {
        val futureTopUpdate = dao.update(id, topic.copy(id = Some(id)))
        futureTopUpdate.map { result =>
          Home.flashing("success" -> "Topic %s has been updated".format(topic.code))
        }.recover {
          case ex: TimeoutException =>
            Logger.error("Problem found in topic update process")
            InternalServerError(ex.getMessage)
        }
      })
  }

and the DAO:
override def update(id: Long, topic: Topic): Future[Int] =
try db.run(filterQuery(id).update(topic))
finally db.close

any idea?

A:

You can show the filterQuery(id) implementation, something similar in a dao of us works well in this way:
  override def update(id: Long, topic: Topic): Future[Int] = {
          db.run(filterQuery(id).update(topic.copy(id))
  }

Notice: topic.copy(id)
And filterQuery is:
def filterQuery(id: Int) = themes.filter(_.id === id)

We using Play 2.6,Scala 2.12, Slick 3 with MYSQL.
Update # 1:
-> Entity:
case class CategoryRow(id: Int, name: String, description: String)

-> Mapping:
trait CategoryMapping {
  self: HasDatabaseConfigProvider[JdbcProfile] =>
  import dbConfig.profile.api._

  private[models] class CategoryTable(tag: Tag)
    extends Table[CategoryRow](tag, "category") {

    def id = column[Int]("id", O.AutoInc, O.PrimaryKey)

    def name = column[String]("name", O.Length(TextMaxLength_250))

    def description = column[String]("description", Nullable)

    def categoryNameAgencyIndex = index("categoryName_agency_idx", (name, agencyId), unique = true)

    override def * = (
      id,
      name,
      description
    ) <> (CategoryRow.tupled, CategoryRow.unapply)
  }

  private[models] val Categories = TableQuery[CategoryTable]
  private[models] val CategoriesInsertQuery = Categories returning Categories.map(_.id)
}

-> REPO
 trait CategoryRepository {
    //...    
      def update(id: Int, category: Category)(implicit agencyId: Int): Future[Int]    
    //...

    }

-> REPOImpl:
@Singleton
class CategoryRepositoryImpl @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)(implicit ec: RepositoryExecutionContext)
  extends CategoryRepository with HasDatabaseConfigProvider[JdbcProfile] with CategoryMapping {

  import dbConfig.profile.api._
//....
     def update(id: Int, category: CategoryRow)(implicit agencyId: Int): Future[Int] =
       db.run(filter(id).update(category.copy(id)))

     private def filter(id: Int) = Categories.filter(_.id === id)
//....
}

-> RepositoryExecutionContex
class RepositoryExecutionContext @Inject()(actorSystem: ActorSystem) extends CustomExecutionContext(actorSystem, "repository.dispatcher")

and aplication.conf:
# db connections = ((physical_core_count * 2) + effective_spindle_count)
fixedConnectionPool = 5

repository.dispatcher {
  executor = "thread-pool-executor"
  throughput = 1
  thread-pool-executor {
    fixed-pool-size = ${fixedConnectionPool}
  }
}

There's some more information about fold in Chapter 3.3 of Essential Slick.

