相关疑难解决方法(0)

实体框架的状态模式

我有一个模型Enquiry,它可以处于两种状态之一(还有更多,但为了这个目的,我将只比较两个):NewClosed. 查询所处的状态取决于用户能够对查询进行什么操作。例如,不能删除已关闭的查询,而可以删除新查询等(基本示例)。

我想坚持这一点,Entity Framework但不确定如何。下面是我的代码。

询问:

public class Enquiry
{
    public int Id { get; set; }
    public string CustomerAccountNumber { get; set; }

    public EnquiryState CurrentState { get; set; }
    public bool CanAddLines { get { return CurrentState.CanAddLines; } }
    public bool CanDelete { get { return CurrentState.CanDelete; } }

    public void ChangeState(EnquiryState currentState)
    {
        CurrentState = currentState;
    }

    public void CloseEnquiry()
    {
        CurrentState.CloseEnquiry();
    }

    /* More methods to change state here …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc design-patterns entity-framework state-pattern

5
推荐指数
1
解决办法
1508
查看次数