2013-07-04 122 views
0

使用PersistenceSpecification的CheckProperty是否有可能在一个只读属性,使用PersistenceSpecification时使用.CheckProperty上一个只读属性

例如,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, "[email protected]") 
    .CheckProperty(x => x.Used, //?? 
    .VerifyTheMappings(); 

但不知道如何可以从这里调用SetAsUsed方法?

回答

0

关闭我的头顶:

new PersistenceSpecification<ForgotPasswordRequest>(Session) 
    .CheckProperty(x => x.Code, "[email protected]") 
    .CheckProperty(x => x.Used, DateTime.Now, (entity, DateTime?) => entity.SetAsUsed()) 
    .VerifyTheMappings(); 
+0

有了这个,我得到:对于财产 '拿来主义' 预期类型 'System.DateTime的',但得到“System.Nullable'1 [System.DateTime的, – Alex