将通用存储库“绑定”到接口

时间:2012-10-12 15:13:16

标签: entity-framework

我目前正在关注以下教程

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

本教程讨论如何实现通用存储库和工作单元。

但是,它似乎没有解释如何将通用存储库“绑定”到接口。

任何人都可以解释如何做到这一点?我需要将我的通用存储库“绑定”到通用接口或派生/自定义接口。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

您只需要定义通用接口:

public interface IGenericRepository<TEntity> 
    where TEntity : class
{
}

让你的课实现它:

public class GenericRepository<TEntity> : IGenericRepository<TEntity> 
    where TEntity : class
{
}