Unit of Work pattern implementation

前端 未结 3 514
悲&欢浪女
悲&欢浪女 2020-12-28 20:58

I am creating an application with ASP.NET MVC and Entity framework code first. I am using repository and unit of work pattern with influence of from following link.

3条回答
  •  情歌与酒
    2020-12-28 21:43

    The Unit of Work pattern is already implemented in Entity Framework.

    The DbContext is your Unit of Work. Each IDbSet is a Repository.

    using (var context = new SchoolContext())   // instantiate our Unit of Work
    {
        var department = context.Departments.Find(id);
    }
    

提交回复
热议问题