我喜欢使用Dapper来满足我的ORM需求,但我知道必须有一种更好的方法来使用存储过程和强类型列表来插入/更新我的sql server数据库.
例如:
我有一首歌曲:
public class Song
{
public int Id { get; set; }
public string title { get; set; }
public string genre { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并且有人提交歌曲列表:
List<Song> songs = new List<Song> {
new Song { Id = 1, title = "Song 1" , genre="rock"},
new Song { Id = 2, title = "Song 2" , genre="disco"}};
Run Code Online (Sandbox Code Playgroud)
我想使用我的存储过程更新数据库,该存储过程插入新歌曲或者如果歌曲已经存在则更新它.我的存储过程有两个输出参数:
@success_added int = 0 and @success_updated int = 0
我的sproc如下:
ALTER PROCEDURE [dbo].[UpdateSong]
@Id int = 0,
@title …Run Code Online (Sandbox Code Playgroud) dapper ×1