开发者

Need help constructing the agile nhibernate entity

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开发者_StackOverflow中文版 int Id { get; set; }
    public virtual string Name { get; set; }
}


Use an enum

Replace your class Stage with an Enum

public enum Stage
{
   Rejected, None, Approved, Etc 
}

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).

Stage nextStage = (Stage)(((int)currentDocument.Stage)++);
Stage previousStage = (Stage)(((int)currentDocument.Stage)--);

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.

  • http://www.codeproject.com/KB/WF/wwf_basics_files.aspx

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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜