我喜歡我在這篇博客文章(http://marekblotny.blogspot.com/2009/04/conventions-after-rewrite.html)中看到的模式,作者正在檢查在應用約定之前是否已經創建了表名更改。Fluent NHibernte Alterations/Conventions
public bool Accept(IClassMap target)
{
//apply this convention if table wasn't specified with WithTable(..) method
return string.IsNullOrEmpty(target.TableName);
}
我使用的字符串長度的約定接口的iProperty:
public class DefaultStringLengthConvention: IPropertyConvention
{
public bool Accept(IProperty property) {
//apply if the string length hasn't been already been specified
return ??; <------ ??
}
public void Apply(IProperty property) {
property.WithLengthOf(50);
}
}
我沒有看到的iProperty公開什麼,告訴我,如果屬性已經設置。這可能嗎?
TIA, Berryl
想法,可能是這筆交易;我不介意爲字符串長度組添加約定,但許多情況都是由該類驅動的一次性事件。因此,如果EmployeeNumber字符串長度應該爲6個字符,則它可以是Employee字段串長度常量,或者是DefaultStringLengthConvention中的if語句。 Thx快速響應。 – Berryl 2009-04-30 17:04:30