Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架、i假设和工作单元。如何实现DAL?_C#_.net_Entity Framework_Orm_Data Access Layer - Fatal编程技术网

C# 实体框架、i假设和工作单元。如何实现DAL?

C# 实体框架、i假设和工作单元。如何实现DAL?,c#,.net,entity-framework,orm,data-access-layer,C#,.net,Entity Framework,Orm,Data Access Layer,使用EF看起来像: public interface IStudentRepository : IDisposable { IEnumerable<Student> GetStudents(); Student GetStudentByID(int studentId); void InsertStudent(Student student); void DeleteStudent(int studentID); void UpdateStud

使用EF看起来像:

public interface IStudentRepository : IDisposable
{
    IEnumerable<Student> GetStudents();
    Student GetStudentByID(int studentId);
    void InsertStudent(Student student);
    void DeleteStudent(int studentID);
    void UpdateStudent(Student student);
    void Save();
}
公共接口是udentrepository:IDisposable
{
IEnumerable GetStudents();
学生GetStudentByID(int studentId);
无效插入学生(学生);
无效删除学生(国际学生ID);
无效更新学生(学生);
作废保存();
}
在这里,我看到了IRepository和UnitOWork的混合

但福勒说,存储库是。因此,Update、Delete和Insert方法应该移动到另一个类中。应该将Save和Save移到实现IUnitOfWork的类中


在我当前的项目中,我们实现了官方文档中提到的IRepository。将来会不会出现问题?一种解决方案是实施CQR,可能是通过事件源,但这需要时间和资源。那么,您如何在项目中实现DAL呢?

您的DAL没有问题


我做的唯一额外的事情是为我的存储库创建一个单例工厂,它是DataService类的一部分。DataService类将交付存储库实例

实体框架已经实现了工作单元(DbContext)和存储库(DbSet)。为什么要给它添加更多的抽象?因为在一般情况下,业务逻辑不应该依赖于DAL的实现细节。如果我们直接使用DbContext和dbset,就会导致紧密耦合。它可能会导致一些问题,例如测试和将EF改为NHibernate或Dapper。