下面是主类文件
Code
namespace EasyTalk.Module
{
/// <summary>
/// SiteAddress object for NHibernate mapped table 'SiteAddress'.
/// </summary>
[Serializable]
public class SiteAddress
{
#region Member Variables
protected string _siteid;
protected string _alias;
protected string _address;
protected string _transporttype;
protected string _description;
protected string _iscurrent;
protected IList<AddressAttributes> _addressattributes;
#endregion
#region Constructors
public SiteAddress() {}
public SiteAddress(string siteid, string alias, string address, string transporttype, string description, string iscurrent)
{
this._siteid= siteid;
this._alias= alias;
this._address= address;
this._transporttype= transporttype;
this._description= description;
this._iscurrent= iscurrent;
}
public SiteAddress(string siteid)
{
this._siteid= siteid;
}
#endregion
#region Public Properties
public virtual string SiteId
{
get { return _siteid; }
set {_siteid= value; }
}
public virtual string Alias
{
get { return _alias; }
set {_alias= value; }
}
public virtual string Address
{
get { return _address; }
set {_address= value; }
}
public virtual string TransportType
{
get { return _transporttype; }
set {_transporttype= value; }
}
public virtual string Description
{
get { return _description; }
set {_description= value; }
}
public virtual string IsCurrent
{
get { return _iscurrent; }
set {_iscurrent= value; }
}
public virtual IList<AddressAttributes> AddressAttributes
{
get { return _addressattributes; }
set {_addressattributes= value; }
}
public virtual void AddItem(AddressAttributes item)
{
if (_addressattributes == null)
_addressattributes = new List<AddressAttributes>();
_addressattributes.Add(item);
}
#endregion
#region Equals And HashCode Overrides
/// <summary>
/// local implementation of Equals based on unique value members
/// </summary>
public override bool Equals( object obj )
{
if( this == obj ) return true;
if( ( obj == null ) || ( obj.GetType() != this.GetType() ) ) return false;
SiteAddress castObj = (SiteAddress)obj;
return ( castObj != null ) &&
this._siteid == castObj.SiteId;
}
/// <summary>
/// local implementation of GetHashCode based on unique value members
/// </summary>
public override int GetHashCode()
{
int hash = ;
hash = * hash * _siteid.GetHashCode();
return hash;
}
#endregion
}
}
下面是明细
Code
namespace EasyTalk.Module
{
/// <summary>
/// AddressAttributes object for NHibernate mapped table 'AddressAttributes'.
/// </summary>
[Serializable]
public class AddressAttributes
{
#region Member Variables
protected decimal _attrid;
protected string _attributekey;
protected string _attributevalue;
protected string _endpointid;
protected string _transporttype;
#endregion
#region Constructors
public AddressAttributes() {}
public AddressAttributes(string attributekey, string attributevalue, string endpointid, string transporttype)
{
this._attributekey= attributekey;
this._attributevalue= attributevalue;
this._endpointid= endpointid;
this._transporttype= transporttype;
}
public AddressAttributes(string endpointid)
{
this._endpointid= endpointid;
}
#endregion
#region Public Properties
public virtual decimal AttrId
{
get { return _attrid; }
set {_attrid= value; }
}
public virtual string AttributeKey
{
get { return _attributekey; }
set {_attributekey= value; }
}
public virtual string AttributeValue
{
get { return _attributevalue; }
set {_attributevalue= value; }
}
public virtual string EndpointId
{
get { return _endpointid; }
set {_endpointid= value; }
}
public virtual string TransportType
{
get { return _transporttype; }
set {_transporttype= value; }
}
#endregion
#region Equals And HashCode Overrides
/// <summary>
/// local implementation of Equals based on unique value members
/// </summary>
public override bool Equals( object obj )
{
if( this == obj ) return true;
if( ( obj == null ) || ( obj.GetType() != this.GetType() ) ) return false;
AddressAttributes castObj = (AddressAttributes)obj;
return ( castObj != null ) &&
this._attrid == castObj.AttrId;
}
/// <summary>
/// local implementation of GetHashCode based on unique value members
/// </summary>
public override int GetHashCode()
{
int hash = ;
hash = * hash * _attrid.GetHashCode();
return hash;
}
#endregion
}
}
配置文件
Code
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!--Build: with lujan99@usa.net Nhibernate template-->
<class name="EasyTalk.Module.SiteAddress,EasyTalk.Module" table="SiteAddress" lazy="true">
<id name="SiteId" column="Site_ID" type="string" unsaved-value="0">
<generator class="assigned" />
</id>
<property name="Alias" column="Alias" type="string" />
<property name="Address" column="Address" type="string" />
<property name="TransportType" column="TransportType" type="string" />
<property name="Description" column="Description" type="string" />
<property name="IsCurrent" column="isCurrent" type="string" />
<bag name="AddressAttributes" lazy="true" cascade="all">
<key column="Endpoint_ID" />
<one-to-many class="EasyTalk.Module.AddressAttributes,EasyTalk.Module" />
</bag>
</class>
</hibernate-mapping>
Code
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!--Build: with lujan99@usa.net Nhibernate template-->
<class name="EasyTalk.Module.AddressAttributes,EasyTalk.Module" table="AddressAttributes" lazy="true">
<id name="AttrId" column="Attr_ID" type="Decimal" unsaved-value="0">
<generator class="native" />
</id>
<property name="AttributeKey" column="AttributeKey" type="string" />
<property name="AttributeValue" column="AttributeValue" type="string" />
<property name="EndpointId" column="Endpoint_ID" type="string" a="true" />
<property name="TransportType" column="TransportType" type="string" />
</class>
</hibernate-mapping>
代码
Code
AddressAttributes s = new AddressAttributes();
//s.Endpoints = e;
//s.AttrId = 1002;
s.EndpointId = "";
s.AttributeKey = "test";
s.AttributeValue = "test";
s.TransportType = "msmq";
//=====================
//a.Endpoints.Add(e);
a.AddItem(e);
//e.AddressAttributes.Add(s);
e.AddItem(s);
SiteAddress sa = new SiteAddress();
sa.Address = "add";
//sa.AddItem(s);
sa.Alias = "alias";
sa.Description = "desc";
sa.IsCurrent = "";
sa.SiteId = "";
sa.TransportType = "msmq";
session.Save(sa);
保存也没有提示错误,但是就是保存不了数据,我单个保存主表也不行,单个保存明细表可以。