具有分层数据结构的存储库模式
我有一个分层数据结构(它存储在一个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
- List of testmethods
- Group etc
- Group
- TestSequence list
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论