在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
方法?
答案 0 :(得分:0)
脱离我的头顶:
new PersistenceSpecification<ForgotPasswordRequest>(Session)
.CheckProperty(x => x.Code, "a@b.com")
.CheckProperty(x => x.Used, DateTime.Now, (entity, DateTime?) => entity.SetAsUsed())
.VerifyTheMappings();