实体框架与WPF数据绑定技术详解
1. 仓储模式与实体框架
仓储模式用于在数据访问层(DAL)添加额外的抽象层,使其他层无法直接访问实体框架(EF)会话,而是使用DAL暴露的仓储类。一个仓储类至少应提供执行基本CRUD操作的方法集和一组基本查询方法,如下是 IRepository 接口的定义:
using System.Collections.Generic;
namespace APRESS.TimeTracker.DataLayer
{
public interface IRepository <T> where T : EntityObject
{
void Insert(T entity);
void Update(T entity);
void Delete(T entity);
IList<T> GetAll();
T GetById(int id);
}
}
为实现这些方法,我们创建一个抽象的 RepositoryBase 类作为具体仓储类的基类:
public abstract class RepositoryBase<T> : IRepository<T> where T : EntityObject
{
private readonly IUnitOfWork unitOfWork;
超级会员免费看
订阅专栏 解锁全文
738

被折叠的 条评论
为什么被折叠?



