具有实体框架的存储库模式4 [英] Repository pattern with Entity Frameworks 4
问题描述
使用这种模式与EF的正确方法是什么?
如何实现这个存储库界面,一个 RepositoryBase< T>
?
public interface IRepository< T>
{
T GetById(object id);
void Save(T entity);
T [] GetAll();
void Delete(T entity);
}
由于某种原因给出的示例将集合公开为IQueryable或IEnumerable。 EF4有一个非常目的的接口 - IObjectSet(或者如果您使用最新的CTP,则为IDbSet)。
Julie Lerman在执行此操作时有着巨大的发言,包括创建一个实现IObjectSet的MockSet,所以你可以做一些断开的单元测试
http://thedatafarm.com/blog/data-access/agile-entity-framework-4-储存库-6-mocks-amp-unit-tests /
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
这篇关于具有实体框架的存储库模式4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!