nHiberbate:每个层次结构表 - SchemaExport 问题
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已在映射中将列设置为非空:
删除
not-null
属性。You've set the columns as not null in the mapping:
Remove the
not-null
attributes.