zoukankan      html  css  js  c++  java
  • 从Entity Framework的实现方式来看DDD中的repository仓储模式运用

    一:最普通的数据库操作


    static void Main(string[] args)
    {
    using (SchoolDBEntities db = new SchoolDBEntities())
    {
    db.Students.Add(new Student() { StudentName = "nihao" });

    db.SaveChanges();
    }
    }


    domain 和 db 是怎么操作。。。

    DbSet<Student> 集合 【用于存放集合】 从名称中可以看出,是一个叫做Student Set的一个集合。。

    可以看出,是一个叫做实体的仓库。。。


    SaveChanges() 模式提交,会从两个仓储中获取添加的domain entity,然后整体性的提交数据库。。。

    执行操作之前,会开启一个transaction。。。两条insert之后, commit transction。。

    UI

    BLL

    DAL


    DBSet => Repository

    DbContext => unitofwork


    //
    // 摘要:
    // Interface implemented by objects that can provide an System.Data.Entity.Infrastructure.IObjectContextAdapter.ObjectContext
    // instance. The System.Data.Entity.DbContext class implements this interface to
    // provide access to the underlying ObjectContext.
    public interface IObjectContextAdapter
    {
    //
    // 摘要:
    // Gets the object context.
    ObjectContext ObjectContext { get; }
    }

    我们在ef4.0,4.1的时候,用的都是objectContext。。。 code first出现之后,都用DBContext进行了封装。。。

  • 相关阅读:
    slim的中间件
    slim中的请求头
    slim中的参数获取
    redis的事务操作
    关于redis有序集合http://www.runoob.com/redis/redis-sorted-sets.html
    linux下的一些命令的笔记
    slim的简单使用
    在windows+nginx的curl操作请求超时的问题
    关于启动php-fpm失败的解决办法
    lintcode-【中等】恢复IP地址
  • 原文地址:https://www.cnblogs.com/dragon-L/p/6517275.html
Copyright © 2011-2022 走看看