非空字段的流畅 Nhibernate Automap 约定
有人可以帮忙吗,我如何指示 automap 不为空 一个专栏?
public class Paper : Entity
{
public Paper() { }
[DomainSignature]
[NotNull, NotEmpty]
public virtual string ReferenceNumber { get; set; }
[NotNull]
public virtual Int32 SessionWeek { get; set; }
}
但我得到以下信息:
<column name="SessionWeek"/>
我知道可以使用 fluence-map 来完成。但我想知道 自动映射方式。
Could some one help, how would I instruct automap to have not-null for
a column?
public class Paper : Entity
{
public Paper() { }
[DomainSignature]
[NotNull, NotEmpty]
public virtual string ReferenceNumber { get; set; }
[NotNull]
public virtual Int32 SessionWeek { get; set; }
}
But I am getting the following:
<column name="SessionWeek"/>
I know it can be done using fluent-map. but i would like to know it in
auto-mapping way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
谢谢。另外,对于引用属性,需要完成ReferenceConvention。这是有效的代码:
Thank you. Also, for reference properties ReferenceConvention need to be done. This is the code that works:
这是我的做法,基本上取自您在代码中看到的链接。还有一些其他有用的约定以及
HTH,
贝里尔
Here is the way I do it, basically taken from the link you see in the code. There are some other useful conventions there as well
HTH,
Berryl
如果您对自动映射结果非常满意,但偶尔需要覆盖它(例如类中的几个属性),我发现为该类实现 IAutoMappingOverride 是实现这一目标的最简单方法:
然后像这样使用它们:
与 ClassMap 类似 - 但是您不需要描述课程中的每个字段。
这种方法与实体框架的 Code First Fluent API 方式非常相似。
If you are mostly happy with Automapping results but occasionally need to override it for say a couple of properties in a class I find implementing a IAutoMappingOverride for that class the easiest way to achieve that:
And then use them like this:
Similar to ClassMaps - but you don't need to describe every field in the class.
This approach is very similar to the Entity Framework's Code First Fluent API way.
默认情况下,Int32 不是可为 null 的类型。 Int32?可以为空,因此只需将其指定为 Int32 即可使其不可为空。
您可以使用约定来自动执行此操作。我不确定要使用哪种约定,但请查看 FluentNHibernate.Conventions.Instances 以找到正确的约定。它会看起来像这样。
只需将此约定添加到您的自动映射中即可。
Int32 is not nullable type by default. Int32? is nullable, so you make it non-nullable just by specifying it as Int32.
You can use conventions to do this automatically. I am not sure which convention to use, but have a look at FluentNHibernate.Conventions.Instances to find the right one. It'll look like this.
Just add this convention to your automapping.
我经常发现我的列不为空,因此我更喜欢制定此约定并仅将列指定为可为空:
I find more often than not, my columns are not null, so I prefer make this convention and only specify columns as nullable: