需要帮助构建敏捷的 nhibernate 实体
我正在创建一个管理文档的 Web 应用程序。这些文件有阶段性。用户将能够从当前阶段拒绝这些文档回到上一阶段。
因此流程将像这样:文档第一阶段已批准>获取下一阶段并将文档阶段设置为下一阶段>文件第一阶段拒绝>获取上一个阶段并将文档阶段设置为上一个阶段。
现在我需要帮助的是如何来回管理各个阶段以及设置我的实体的最佳方法是什么?
示例实体
public class Document
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Stage Stage { get; set; }
}
public class Stage
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
I am creating a web application that manages documents. These documents have stages. Users will be able to reject these documents from the current stage back to the previous stage.
So the flow will be like this Document stage one approved > Get next stage and set document stage to next stage > Document stage one REJECTED > Get previous stage and set document stage to previous stage.
Now what I need help with is how to manage the stages back and forth and what is the best way to setup my entities?
Example Entities
public class Document
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Stage Stage { get; set; }
}
public class Stage
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用枚举 用
枚举替换您的类 Stage
在您的 NHibernate 映射 simplay 中将 Stage 枚举添加到您的映射
在你的数据库中,你可以简单地创建一个 int32 的 Stage 列,Nhibernate 将弄清楚如何自动持久化和加载枚举。
使用枚举的优点是您始终可以将枚举转换为 int 并递减或递增以获得上一个或下一个阶段(假设您只是将它们添加到 0..N 中)。
否则,您可以使用 linq 查询来获取上一个或下一个步骤。
编辑
到目前为止,您的要求中还没有列出您需要任何通用工作流程的复杂性。这是一个示例应用程序,它使用 WWF 以及类似于您所需的文档审批系统。
直到您真正需要 WWF 的复杂性为止。我建议您使用枚举,然后在需求发生变化时进行重构。这样您就不会实现“以防万一”的功能。
Use an enum
Replace your class Stage with an Enum
In your NHibernate mapping simplay add the Stage enum to your map
<property name="Stage"></property>
In your db you can simply create the Stage column to an int32 and Nhibernate will figure out how to persist and load the enum automagically.
The advantage of using an enum is that you can always cast the enum to an int and decrement or increment to get the previous or next stage (assuming that you are simply adding them in 0..N).
Otherwise you can use a linq query to get the previous or next steps.
Edit
So far in your requirements you haven't listed that you need anything of the complexity of a generic workflow. Here is a sample app which uses WWF with a document approval system similiar to what you require.
Until you actually need something of the WWF complexity. I would recommend that you use the enum and then refactor when your requirements change. This way you're not implementing a feature "just in case".