nHiberbate:每个层次结构表 - SchemaExport 问题

发布于 2024-11-12 05:56:25 字数 2335 浏览 3 评论 0原文

我正在使用 nhibernate 映射以下类:

public class DeviceConfig : EntityBase
{
    public virtual string Name
    {
        get { return m_Name; }
        set { SetValue(ref m_Name, value); }
    }
    public virtual string Description
    {
        get { return m_Description; }
        set { SetValue(ref m_Description, EmptyStringIfValueNull(value)); }
    }
}

 public class DeviceConfigEmail : DeviceConfig 
{
    public virtual string SmtpServer
    {
        get { return m_SmtpServer; }
        set { SetValue(ref m_SmtpServer, EmptyStringIfValueNull(value)); }
    }
}

public class DeviceConfigSMS : DeviceConfig
{
    public virtual string SmsServer
    {
        get { return m_SmsServer; }
        set { SetValue(ref m_SmsServer, EmptyStringIfValueNull(value)); }
    }

}

使用以下映射文件:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  default-access="field.pascalcase-m-underscore">
  <class name="MyNamespace.DeviceConfig, MyNamespace" table="DeviceConfig" lazy="false">
      <id name="ID" access="property" column="DeviceConfigID" unsaved-value="-1">
      <generator class="identity" />
    </id>

    <discriminator column="Discriminator"/>

    <version name="Version" column="Version"/>

    <property name="Name" not-null="true"/>
    <property name="Description" not-null="true"/>


    <subclass name="MyNamespace.DeviceConfigEmail, MyNamespace" discriminator-value="Email" lazy="false">
      <property name="SmtpServer" not-null="true"  />
    </subclass>

    <subclass name="MyNamespace.DeviceConfigSMS, MyNamespace" discriminator-value="SMS" lazy="false">
      <property name="SmsServer" not-null="true"  />
    </subclass>

  </class>
</hibernate-mapping>

我正在对表进行按层次结构表数据建模,如下所示:

table: DeviceConfig
- DeviceConfigID (PK, int, not null)
- Discriminator (varchar(20), not null)
- Name (varchar(50), not null)
- Description (varchar(200), not null)
- SmtpServer (varchar(30), null)
- SmsServer (varchar(30), null)

这一切都很好,并且适用于我的 SQL 数据库。

我现在想做一个 SchemaExport 对 Sqlite 进行一些内存测试。当我使用架构导出生成此表时,SmtpServer 和 SmsServer 列都会生成为not null

我做错了什么吗?如何使这些列生成为可为空?

谢谢,

保罗

I am using nhibernate to map the following classes:

public class DeviceConfig : EntityBase
{
    public virtual string Name
    {
        get { return m_Name; }
        set { SetValue(ref m_Name, value); }
    }
    public virtual string Description
    {
        get { return m_Description; }
        set { SetValue(ref m_Description, EmptyStringIfValueNull(value)); }
    }
}

 public class DeviceConfigEmail : DeviceConfig 
{
    public virtual string SmtpServer
    {
        get { return m_SmtpServer; }
        set { SetValue(ref m_SmtpServer, EmptyStringIfValueNull(value)); }
    }
}

public class DeviceConfigSMS : DeviceConfig
{
    public virtual string SmsServer
    {
        get { return m_SmsServer; }
        set { SetValue(ref m_SmsServer, EmptyStringIfValueNull(value)); }
    }

}

With the following Mapping file:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  default-access="field.pascalcase-m-underscore">
  <class name="MyNamespace.DeviceConfig, MyNamespace" table="DeviceConfig" lazy="false">
      <id name="ID" access="property" column="DeviceConfigID" unsaved-value="-1">
      <generator class="identity" />
    </id>

    <discriminator column="Discriminator"/>

    <version name="Version" column="Version"/>

    <property name="Name" not-null="true"/>
    <property name="Description" not-null="true"/>


    <subclass name="MyNamespace.DeviceConfigEmail, MyNamespace" discriminator-value="Email" lazy="false">
      <property name="SmtpServer" not-null="true"  />
    </subclass>

    <subclass name="MyNamespace.DeviceConfigSMS, MyNamespace" discriminator-value="SMS" lazy="false">
      <property name="SmsServer" not-null="true"  />
    </subclass>

  </class>
</hibernate-mapping>

I am doing table per hierarchy data modelling to a table as follows:

table: DeviceConfig
- DeviceConfigID (PK, int, not null)
- Discriminator (varchar(20), not null)
- Name (varchar(50), not null)
- Description (varchar(200), not null)
- SmtpServer (varchar(30), null)
- SmsServer (varchar(30), null)

This is all well and good, and works against my SQL database.

I now want to do a SchemaExport to do some in memory testing against Sqlite. When I generate this table with a schema export, both SmtpServer and SmsServer columns get generated as not null.

Is there something I am doing wrong? How can I get these columns to generate as nullable?

Thanks,

Paul

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼中杀气 2024-11-19 05:56:25

您已在映射中将列设置为非空:

<property name="SmtpServer" not-null="true" />
....
<property name="SmsServer" not-null="true" /> 

删除 not-null 属性。

You've set the columns as not null in the mapping:

<property name="SmtpServer" not-null="true" />
....
<property name="SmsServer" not-null="true" /> 

Remove the not-null attributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文