我根据自己的理解汇总了一个如何使用工作单元和存储库模式的示例.如果我以正确的方式实施这个,请问有谁能告诉我吗?如果我不是,我该如何改进呢?
在此先感谢,非常感谢.
我有一个带有两个实体的EF模型:Topic和Subtopic.EF模型称为CommonGood.
工作单位:
/// <summary>
/// Implementation of a UnitOfWork class
/// </summary>
public static class UnitOfWork
{
/// <summary>
/// Gets the default context
/// </summary>
/// <returns>A new instance of the default context</returns>
public static CommonGoodEntities GetContext()
{
return new CommonGoodEntities();
}
}
Run Code Online (Sandbox Code Playgroud)
IGenericRepository:
public interface IRepository<T>
{
/// <summary>
/// Gets all entities
/// </summary>
/// <returns>All entities</returns>
IEnumerable<T> GetAll();
/// <summary>
/// Gets all entities matching the predicate
/// </summary>
/// <param name="predicate">The filter clause</param> …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc entity-framework unit-of-work repository-pattern