0

在只读属性上使用.CheckProperty时是否可以使用?PersistenceSpecification

例如,Used作为只读属性的类,作为SetAsUsed设置属性的方法:

public class MyClass
{
    public virtual int Id { get; set; }
    public virtual string Code { get; set; }

    public virtual DateTime? Used { get; private set; }

    public virtual void SetAsUsed()
    {
        Used = DateTime.Now;
    }
}

我想做一个持久性规范,例如:

new PersistenceSpecification<ForgotPasswordRequest>(Session)
    .CheckProperty(x => x.Code, "a@b.com")
    .CheckProperty(x => x.Used, //??
    .VerifyTheMappings();

但不确定如何SetAsUsed从这里调用该方法?

4

1 回答 1

0

在我的头顶上:

new PersistenceSpecification<ForgotPasswordRequest>(Session)
    .CheckProperty(x => x.Code, "a@b.com")
    .CheckProperty(x => x.Used, DateTime.Now, (entity, DateTime?) => entity.SetAsUsed())
    .VerifyTheMappings();
于 2013-07-04T22:03:32.777 回答