Skip to content

Instantly share code, notes, and snippets.

@pimbrouwers
Last active September 14, 2022 11:27
Show Gist options
  • Save pimbrouwers/3222f1ed5007e20af217d0c9a28728e3 to your computer and use it in GitHub Desktop.
Save pimbrouwers/3222f1ed5007e20af217d0c9a28728e3 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Project.Repo
{
public interface IMapper<TEntity> where TEntity : class
{
IEnumerable<PropertyInfo> Properties { get; }
Type Type { get; }
Dictionary<string, object> ReadPropertyValues(TEntity entity, IEnumerable<string> properties);
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
namespace Project.Repo
{
public interface IRepository<TEntity> where TEntity : class
{
ISqlConnectionFactory ConnectionFactory { get; }
ITable<TEntity> Table { get; }
Task<int> Execute(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType commandType = CommandType.Text, IDbConnection conn = null);
Task<IEnumerable<T>> Query<T>(string sql, object param = null, IDbTransaction transaction = null, CommandType commandType = CommandType.Text);
Task<T> First<T>(string sql, object param = null, IDbTransaction transaction = null, CommandType commandType = CommandType.Text);
Task<IEnumerable<TEntity>> GetAll();
Task<TEntity> Get(int id);
Task<int> Create(TEntity entity, IDbTransaction transaction = null);
Task<bool> Update(TEntity entity, IDbTransaction transaction = null);
Task<bool> Delete(TEntity entity, IDbTransaction transaction = null);
}
}
using System.Data.SqlClient;
using System.Threading.Tasks;
namespace Project.Repo
{
public interface ISqlConnectionFactory
{
string ConnectionString { get; }
Task<SqlConnection> CreateOpenConnection();
}
}
namespace Project.Repo
{
public interface ITable<TEntity> where TEntity : class
{
IMapper<TEntity> Mapper { get; }
string[] Fields { get; }
string[] FieldsQualified { get; }
string Key { get; }
string[] NonKeyFields { get; }
string[] NonKeyFieldsQualified { get; }
string Name { get; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment