[英]NHibernate mapping class
I am new in NHibernate and need help. 我是NHibernate的新手,需要帮助。 I have two classes: 我有两节课:
class Pop3
{
public virtual long Id { set; get; }
public virtual string HostName { set; get; }
public virtual int Port { set; get; }
public virtual bool UseSsl { set; get; }
}
class Email
{
public virtual long Id { set; get; }
public virtual string UserName { set; get; }
public virtual string Password { set; get; }
public virtual Pop3 Host { set; get; }
}
I need to map them to NHibernate (uses Sqlite). 我需要将它们映射到NHibernate(使用Sqlite)。 That is easy with Pop3 class Pop3类很容易
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TestAsm"
namespace="TestAsm.Entity.Mail">
<class name="Pop3" table="pop3hosts">
<id name="Id">
<generator class="identity" />
</id>
<property name="HostName" />
<property name="Port" />
<property name="UseSsl" />
</class>
</hibernate-mapping>
But how can I map Email class contains Pop3 class as property? 但是如何映射Email类包含Pop3类作为属性? My be i need to set Pop3.Id in Host property? 我需要在Host属性中设置Pop3.Id吗? But I think it is wrong way. 但是我认为这是错误的方式。
This mapping belongs to the most basic, typical and well documented, I would say 我会说,此映射属于最基本,最典型且有据可查的
An example, where the Pop3
class is mapped with many-to-one
over the column Pop3Id
: 一个例子,其中Pop3
类被映射与many-to-one
在塔Pop3Id
:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="TestAsm"
namespace="TestAsm.Entity.Mail">
<class name="Email" table="email_table">
<id name="Id" generator="identity" />
<property name="UserName" />
<property name="Password" />
<many-to-one name="Host" column="Pop3Id" class="Pop3 " />
</class>
</hibernate-mapping>
Please check the Chapter 21. Example: Parent/Child 请检查第21章。示例:父母/子女
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.