小编Wes*_*ley的帖子

与 Dapper .NET 的交易

我目前在一层中有两个类,它们执行将数据包含在数据库中的操作:

using Dapper;
using System;
using System.Data.SqlClient;
using System.Linq;

namespace repositories
{
    public class DAOBook
    {
        private readonly string _connection;

        public DAOBook(string databaseConnection)
        {
            _connection = databaseConnection;
        }

        public bool IncludeBook(string title)
        {
            try
            {
                using (var connection = new SqlConnection(_connection))
                {
                    var sql = $@"
                                INSERT INTO books
                                  (title)
                                VALUES
                                  ('{title}' ";

                    var result = connection.Execute(sql);

                    return result != 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}", ex);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)
using Dapper;
using System;
using …
Run Code Online (Sandbox Code Playgroud)

.net c# oracle transactions dapper

3
推荐指数
1
解决办法
6175
查看次数

标签 统计

.net ×1

c# ×1

dapper ×1

oracle ×1

transactions ×1