在readonly属性上使用PersistenceSpecification的CheckProperty

时间:2013-07-04 09:34:07

标签: c# nhibernate fluent-nhibernate

在readonly属性上使用.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方法?

1 个答案:

答案 0 :(得分:0)

脱离我的头顶:

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