2013-07-04 123 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