我如何获得流畅的 nhibernate 来保存“null”到数据库中查找未初始化的变量
我有一个这样的类:
public class test
{
public virtual int Id { get; private set; }
public virtual char testType { get; set; }
public virtual char testType2 { get; set; }
}
当我创建这个类时,但不指定 testType2,我希望该值在数据库中为“null”。相反,该值是一个空字符。我发现强制其为空的一种方法是使用 char?对于类型。但是,这显然不适用于字符串(无法编译),而且我真的不想弄乱可空类型。有没有办法让 nhibernate 始终将未初始化的变量保存为“null”?
编辑:未初始化的字符串变量在数据库中保存为“null”。我仍然需要 char 和 int 的解决方案。
I have a class like this:
public class test
{
public virtual int Id { get; private set; }
public virtual char testType { get; set; }
public virtual char testType2 { get; set; }
}
When I create this, but don't specificy testType2, I want the value to be "null" in the database. Instead, the value is an empty char. One way that I found to force this to be null is to use char? for the type. However, this apparently doesn't work for strings (doesn't compile), and I really don't want to mess with nullable types. Is there any way to get fluent nhibernate to always save uninitialized variables as "null"?
Edit: uninitialized string variables are saved as "null" in the db. I still need a solution for char and int.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的就是添加一个 ?在类型之后。
All you need to do is to add a ? after the type.