具有实体框架的存储库模式4 [英] Repository pattern with Entity Frameworks 4

查看:142
本文介绍了具有实体框架的存储库模式4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用NHibernate与存储库接口。



使用这种模式与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

http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-6-mocks-amp-unit-tests/

这篇关于具有实体框架的存储库模式4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆