dthhlf1777 2014-08-20 05:52
浏览 33
已采纳

数据映射器如何映射2+ dbms表之间的关系?

I have two data domains, Student and Course, and relative data mappers, StudentMapperMySQL and CourseMapperMySQL. Now I want to implement a third data mapper for fetching both data, especially for taking advantage of SQL JOIN (SELECT ... FROM students JOIN courses ON .... WHERE ...). What should the select()/fetch() method return? and how should it work via a repository pattern implementation?

  • 写回答

1条回答 默认 最新

  • doulu4534 2014-08-20 08:26
    关注

    It looks like you are creating new aggregate root just for query purpose, which is totally fine if you would like to use CQRS.

    Every AR should have its own repository, so you should make AR StudentCourses and StudentCoursesRepository (something from your ubiqutious language).

    You should call that repository to get student course data repo.getCoursesForStudent(student_id) or for all at once repo.getStudentsWithCourses().

    Repositories should return only aggregate roots, so in return you would get an aggregate root or list of them.

    Such AR would look like that:

    class StudentCourses:
        studentName Name (VO)
        studentId AggregateId (VO)
        courseList Course[0..*] (Entity)
    
    class Course:
        your course data
    

    What is important here is that you have different models for command and for query, so you can have two different Course model entities in your system. Course in command model is probably an aggregate root, while in query model it's not.

    I suppose that this answer might be a bit hard to understand, but I did my best. Anyway I'm not a DDD expert so there might be other ways to do that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录