Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在只读属性上使用PersistenceSpecification的CheckProperty_C#_Nhibernate_Fluent Nhibernate - Fatal编程技术网

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,