问题描述
我试图让我的头左右,其中聚集根源在于我的实体框架数据模型,所以我知道什么仓库我需要创建。
如果我跟在关系数据库术语了一秒钟,我有一个ExceptionGroup对象和异常对象(不是System.Exception的!)。一个例外属于一个ExceptionGroup并没有ExceptionGroup就不能存在。
我是否应该为每个对象或含有这两种方法的单个存储库的存储库?如果我有一个单一的存储库的方法是如下...
FindAllExceptionsByExceptionGroup(INT组ID)
AddExceptionGroup(ExceptionGroup ExceptionGroup) - 因为异常不能没有一组存在。
AddException(DataAccess.Exception例外)
DeleteExceptionGroupByID(INT组ID)
DeleteExceptionByID(INT ExceptionID)
DeleteExceptionByGroup(INT组ID)
如果我理解正确的模型,这听起来像你会对 ExceptionGroup
存储库和 ExceptionGroup
对象将封装访问和操作上的异常
实例(为前,通过使它们的集合)。以这种方式,这两个类之间的强制关系变得很明显。
杰夫胸骨具有优良的回答类似的问题在这里:什么是聚合根他的命令的例子/ LineItem的似乎是类似的。
I am trying to get my head around where the aggregates roots lie in my entity framework data model so I know what repositories I need to create.
If I talk in relational database terms for a second, I have an ExceptionGroup object and an Exception object (not system.exception!). An Exception belongs to an ExceptionGroup and cannot exist without an ExceptionGroup.
Should I have a repository for each object or a single repository containing methods for both? If I was to have a single repository the methods would be as follows...
FindAllExceptionsByExceptionGroup(int GroupID)
AddExceptionGroup(ExceptionGroup ExceptionGroup) - because an exception cannot exist without a group.
AddException(DataAccess.Exception Exception)
DeleteExceptionGroupByID(int GroupID)
DeleteExceptionByID(int ExceptionID)
DeleteExceptionByGroup(int GroupID)
If I understand your model correctly, it sounds like you would have a repository for ExceptionGroup
and the ExceptionGroup
object would encapsulate access and operations on Exception
instances (for ex., by exposing a collection of them). In this way, the forced relationship between the two classes becomes very apparent.
Jeff Sternal has an excellent answer to a similar question here: What's an Aggregate Root? His example of Order / LineItem seems analogous.
这篇关于Repository模式 - 聚合根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!