I used to use NHibernate with repository interfaces.
What is the proper way to use this pattern with EF?
How can I implement this repository interface, for a RepositoryBase<T>
?
public interface IRepository<T>
{
T GetById(object id);
void Save(T entity);
T[] GetAll();
void Delete(T entity);
}
For some reason all of the examples given expose the collections as IQueryable or IEnumerable. EF4 has an interface for this very purpose - IObjectSet (or IDbSet if you're using the latest CTP).
Julie Lerman has a tremendous post on doing this, including creating a MockSet that implements IObjectSet, so you can do some disconnected unit testing
http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-6-mocks-amp-unit-tests/
It's not really a whole lot different than any other ORM. Here's an example: http://blogs.microsoft.co.il/blogs/gilf/archive/2010/01/20/using-repository-pattern-with-entity-framework.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With