2013-02-10 80 views
1

如果我有我的域名實體User具有財產代碼生成UpperEmail財產

public virtual string UpperEMail { get; protected set; } 

,它是這樣映射

Property(x => x.UpperEmail, m => 
{ 
    m.Length(150); 
    m.NotNullable(true); 
    m.UniqueKey("UniqueUpperEmail"); 
    m.Access(Accessor.Field); 
}); 

如何生成測試數據此UpperEmail屬性。

Account account = new Account() 
{ 
    Id = Guid.NewGuid(), 
    Email = "[email protected]", 
    UpperEmail = "[email protected]" 
}; 

Ofcourse我收到以下錯誤(我不能設置值設置的原因訪問者是無法訪問)

非空屬性引用null或瞬時值 Account.UpperEmail

如何解決這個問題?

回答

2

你有沒有認爲你需要UpperEmail只get訪問

public virtual string UpperEMail { get Email.ToUpper(); }