私はDAL with dapperが好きで、同様のことをやっているのを見ています。 Baseリポジトリクラスの使い方、そしてサービス層からの呼び出し方法私はまた、サービス層のトランザクションスコープを使用します。いずれかがサービス層の引数を渡すためのサンプルソリューションを提供していますか?または任意の代替ソリューション?サービスリポジトリクラスin C#とdapper
public class Repository<T> where T : class
{
protected readonly IComplianceConnection Connection;
public Repository(IComplianceConnection connection)
{
Connection = connection;
}
public IEnumerable<T> Get(string query, object arguments)
{
IList<T> entities;
using (var connection = Connection.OpenConnection())
{
entities = connection.Query<T>(query, arguments, commandType: CommandType.StoredProcedure).ToList();
}
return entities;
}
public T GetSingleOrDefault(string query, object arguments)
{
T entity;
using (var connection = Connection.OpenConnection())
{
entity =
connection.Query<T>(query, arguments, commandType: CommandType.StoredProcedure).SingleOrDefault();
}
return entity;
}
public void Update(string query, object arguments)
{
using (var connection = Connection.OpenConnection())
{
connection.Execute(query, arguments, commandType: CommandType.StoredProcedure);
}
}
public int ExecuteScalar(string query, object arguments)
{
var id = 0;
using (var connection = Connection.OpenConnection())
{
id = connection.ExecuteScalar<int>(query, arguments, commandType: CommandType.StoredProcedure);
}
return id;
}
}