流畅的 NHibernte 变更/约定
我喜欢我在这篇博文中看到的模式(http://marekblotny .blogspot.com/2009/04/conventions-after-rewrite.html),作者在应用约定之前检查是否已进行表名更改。
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, 贝里尔
I like the pattern I saw in this blog post (http://marekblotny.blogspot.com/2009/04/conventions-after-rewrite.html), where the author is checking to see if a table name alteration has already been made before applying a convention.
public bool Accept(IClassMap target)
{
//apply this convention if table wasn't specified with WithTable(..) method
return string.IsNullOrEmpty(target.TableName);
}
The convention interface I'm using for a string length is 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);
}
}
I don't see where IProperty exposes anything that tells me if the property has already been set. Is this possible?
TIA,
Berryl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.WithLengthOf()
将“更改”(Action
) 添加到生成 XML 映射时要应用的更改列表中。 不幸的是,该字段是private
并且没有属性可以访问更改列表,因此恐怕(当前)无法检查属性映射是否具有WithLengthOf应用于它。
.WithLengthOf()
adds an "alteration" (Action<XmlElement>
) to the list of alterations to apply when the XML mapping is generated. Unfortunately, that field isprivate
and there is no property to access the alteration list, so I'm afraid there is (currently) no way to check if a property map has hadWithLengthOf
applied to it.在出现更好的替代方案之前,您可以使用
HasAttribute("length")
。Until a better alternative comes along, you can use
HasAttribute("length")
.为了在代码中阐明 Stuart 和 Jamie 所说的内容,以下是有效的方法:
To clarify in code what Stuart and Jamie are saying, here's what works: