C
csharper
Hi, I am interested in implementing the Repository pattern for my data store. I searched and found the following article.
http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html
In the article, the generic IRepository interface is as follows:
public interface IRepository<T> where T : class
{
T GetById(int id);
IQueryable<T> GetAll();
void InsertOnSubmit(T entity);
void DeleteOnSubmit(T entity);
[Obsolete("Units of Work should be managed externally to the Repository.")]
void SubmitChanges();
}
My question is with regard to the GetById method, which takes an int argument. Since this is a generic interface, I would assume that the GetById method should also take a generic type argument. Suppose in my business domain, Book's ID is of type varchar(13), and Author's ID is of type int, then this IRepository interface which has declared GetById(int id) won't be applicable to Book.
What's the best practice for this issue? Should I declare GetById as shownbelow?
T GetById(object id);
Any thoughts on this? Thanks.
http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html
In the article, the generic IRepository interface is as follows:
public interface IRepository<T> where T : class
{
T GetById(int id);
IQueryable<T> GetAll();
void InsertOnSubmit(T entity);
void DeleteOnSubmit(T entity);
[Obsolete("Units of Work should be managed externally to the Repository.")]
void SubmitChanges();
}
My question is with regard to the GetById method, which takes an int argument. Since this is a generic interface, I would assume that the GetById method should also take a generic type argument. Suppose in my business domain, Book's ID is of type varchar(13), and Author's ID is of type int, then this IRepository interface which has declared GetById(int id) won't be applicable to Book.
What's the best practice for this issue? Should I declare GetById as shownbelow?
T GetById(object id);
Any thoughts on this? Thanks.