I would like to answer # 3 ...
I think this is less "smelly" and more "lazy." Here is a typical "repository" that I saw around the internet ...
public interface IRepository {
IQueryable<T> All<T>();
IQueryable<T> Find<T>(Expression<Func<T, bool>> expression);
T Single<T>(Expression<Func<T, bool>> expression);
T Add<T>(T objectToAdd);
void Delete<T>(T objectToDelete);
T Update<T>(T objectToUpdate);
}
To my knowledge, this is a smaller repository and more of a “session” or “unit of work”. This is a convenient way to abstract from the database technology used and just talk with an extremely common interface. So rename it to ISession. This is a sample I made recently.
public class PeopleRepository {
private readonly ISession session;
public PeopleRepository(ISession session) {
this.session = session;
}
public virtual IEnumerable<Person> Active() {
return session.Find<Person>(p => p.Active).OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
}
public virtual IEnumerable<Person> ByLastName(string name) {
return session.Find<Person>(p => p.Active && p.LastName.StartsWith(lastName)).OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
}
public virtual void DeletePerson(int personId) {
var person = session.Single<Person>(p => p.Id == personId);
person.Active = false;
session.Update(person);
}
}
ISession . , PersonRepository , Person.
, .