Does it makes sense to use the Repository pattern without the use of LINQ or some other ORM? I am writing an application in MONO and using MySQL, was thinking of using the repo
It's absolutely possible. But you should move queries to repository site and implement one repository per class. For example:
public abstract class GenericRepository : IRepository {
public virtual T Get(Identity id) where T : PersistentDocument {
using (IDbConnection connection = GetConnection())
using(IDbCommand command = CreateGetCommand(id, connection)) {
using (IDataReader reader = command.ExecuteReader()) {
var mapper = DaHelper.GetMapper();
return mapper.Map(reader);
}
}
}
protected virtual IDbCommand CreateGetCommand(Identity id, IDbConnection connection) {
IDbCommand command = connection.CreateCommand();
command.CommandText = String.Format("SELECT * FROM {0} e WHERE e.id = ?", TableName);
command.Parameters.Add(id.ToGuid());
return command;
}
protected abstract string TableName { get; }
}
public class UserRepository: GenericRepository, IUserRepository
{
protected override string TableName { get { return "users"; } }
public User GetByEmail(string email)
{
using (IDbConnection connection = GetConnection())
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = String.Format("SELECT * FROM {0} e WHERE e.email = ?", TableName);
command.Parameters.Add(email);
using (var reader = command.ExecuteReader())
return DaHelper.GetMapper().Map(reader);
}
}
}