C# 在只读属性上使用PersistenceSpecification的CheckProperty
在只读属性上使用C# 在只读属性上使用PersistenceSpecification的CheckProperty,c#,nhibernate,fluent-nhibernate,C#,Nhibernate,Fluent Nhibernate,在只读属性上使用PersistenceSpecification时,是否可以使用.CheckProperty 例如,用作只读属性的类,以及setased用作设置属性的方法的类: public class MyClass { public virtual int Id { get; set; } public virtual string Code { get; set; } public virtual DateTime? Used { get; private set
PersistenceSpecification
时,是否可以使用.CheckProperty
例如,用作
只读属性的类,以及setased
用作设置属性的方法的类:
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();
新的PersistenceSpecification(会话)
.CheckProperty(x=>x.Code,“a@b.com")
.CheckProperty(x=>x.已使用,/??
.验证应用程序();
但我不知道如何从这里调用
SetAsUsed
方法?我想:
new PersistenceSpecification<ForgotPasswordRequest>(Session)
.CheckProperty(x => x.Code, "a@b.com")
.CheckProperty(x => x.Used, DateTime.Now, (entity, DateTime?) => entity.SetAsUsed())
.VerifyTheMappings();
新的PersistenceSpecification(会话)
.CheckProperty(x=>x.Code,“a@b.com")
.CheckProperty(x=>x.Used,DateTime.Now,(entity,DateTime?=>entity.setased())
.验证应用程序();
这样,我得到:对于属性“Used”预期类型“System.DateTime”但“get”System.Nullable`1[[System.DateTime,