我一直在与这个战斗至少两个小时,因为我对MSSql的了解非常有限,想要求帮助:
val action: DBIO[Seq[Int]] = sql"""
DECLARE @id int;
EXEC AdsContent.TemplatesCreate
@ID_ClientSites = ${bannerElementTemplatesDto.idClientSites},
@Title = ${bannerElementTemplatesDto.title},
@FileName = ${bannerElementTemplatesDto.fileName},
@Description1 = ${bannerElementTemplatesDto.description},
@Description2 = ${bannerElementTemplatesDto.description},
@DID_BannerElementStatus = ${bannerElementTemplatesDto.didBannerElementStatus},
@TemplateVersion = ${bannerElementTemplatesDto.templateVersion},
@ID_AgencyUsers = ${bannerElementTemplatesDto.idAgencyUser},
@IsReadOnly = ${bannerElementTemplatesDto.readOnly},
@CanBeUsedInProductTargeting = ${bannerElementTemplatesDto.canBuUsedInProductionTargeting},
@ID_OwnedBy = ${bannerElementTemplatesDto.ownedBy},
@ID_CreatedBy = ${bannerElementTemplatesDto.createdById},
@ID_BannerElementTemplates = @id OUTPUT;
select @id as 'id'
""".as[Int]
db.run(action).map { x =>
x match {
case Seq() => throw new SQLException("No id was returned from the when inserting template to DB")
case Seq(a) => a
case Seq(xs @ _*) => throw new SQLException(s"Multiple values were returned when inserting template to DB: $xs")
}
}
这个编译它可以将数据插入到数据库中,但我无法获得生成的id。
id与@ID_BannerElementTemplates
相关联,并以此方式设置过程:
SELECT @ID_BannerElementTemplates = SCOPE_IDENTITY()
我总是得到1
。