具有分层数据结构的存储库模式

发布于 2025-01-06 11:01:44 字数 1084 浏览 5 评论 0原文

我有一个分层数据结构(它存储在一个xml文件中),我想将数据层封装在某种接口中以从业务层访问数据。

似乎具有工作单元的存储库模式可能是封装数据模型的好方法,但我真的不知道如何做到这一点..:

我的数据分组如下

  • TestPlan
    • 测试序列列表
      • 测试方法
      • 组参考
      • 测试方法等
    • 测试方法组列表
        • 测试方法列表
          • 测试方法
          • 组参考
          • 测试方法
      • 群组等

我尝试了几种方法,但似乎 Repository/UoW patteen 更适合映射平面表而不是分层结构。

例如,制作

interface IRepository<T>
{
    void Add(T entity);
    void Remove(T entity); 
    T GetByName(string name);
    IEnumerable<T> GetAll();
}

And then a

interface IUnitOfWork
{
    IRepository<Group> GroupsOfTestmethods { get; }
    IRepository<groupitembase> TestSequence { get; } // groupitembase is base class for TestMethod and GroupReference
    void Save();
}

Now,如果我想要一个 TestMethod,我必须遍历 TestSequence 列表和 GroupsOfTestmethods 中的所有组以确保找到它。然而,如果有一个通用函数来获取 TestMethod 项,无论它位于哪个列表中,那就太好了。

关于如何构建存储库/UoW 实现或分层结构的任何数据访问层有什么建议吗?

问候安德斯

I have a hierarchical datastructure (it is stored in an xml file) and I want to encapsulate the data layer in some kind of interface to access the data from the bussiness layer.

It seems that repository pattern with unit of work could be a good way of encapsulating the datamodel, but I can't really see how to do it..:

My data is grouped as follows

  • TestPlan
    • TestSequence list
      • TestMethod
      • GroupReference
      • TestMethod etc
    • GroupsOfTestmethods list
      • Group
        • List of testmethods
          • TestMethod
          • GroupReference
          • TestMethod
      • Group etc

I've tried several approached, but it seems that Repository/UoW patteen is good for mapping flat tables rather than a hierarchical structure.

For instance, making

interface IRepository<T>
{
    void Add(T entity);
    void Remove(T entity); 
    T GetByName(string name);
    IEnumerable<T> GetAll();
}

And then a

interface IUnitOfWork
{
    IRepository<Group> GroupsOfTestmethods { get; }
    IRepository<groupitembase> TestSequence { get; } // groupitembase is base class for TestMethod and GroupReference
    void Save();
}

Now, if I want a TestMethod I have to traverse both the TestSequence list and all Groups in GroupsOfTestmethods to be sure to find it. However it would be nice to have a common function for getting a TestMethod item regardless in what list it is located in..

Any suggestions on how to construct a Repository/UoW implementation, or any data access layer to a hierarchical structure?

Regards Anders

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文