Hibernate version: 1.2.0 Beta 2
How do I serialize an object with collections. When I set the collection as a generic.ilist<> xmlserializer states it can not serialize interfaces. When I set the collection as generic.list<>, nhibernate can not cast PersistentGenericBag to generic.list<>.
Class:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace RateChart.DataAccess.Entities
{
[Serializable()]
public class RateChartRequest
{
private int _RateChartRequestID;
public virtual int RateChartRequestID
{
get { return _RateChartRequestID; }
set { _RateChartRequestID = value; }
}
private string _RequestStatus;
public virtual string RequestStatus
{
get { return _RequestStatus; }
set { _RequestStatus = value; }
}
private bool _EmailRateChart;
public virtual bool EmailRateChart
{
get { return _EmailRateChart; }
set { _EmailRateChart = value; }
}
private bool _PrintRateChart;
public virtual bool PrintRateChart
{
get { return _PrintRateChart; }
set { _PrintRateChart = value; }
}
private bool _SampleRateChart;
public virtual bool SampleRateChart
{
get { return _SampleRateChart; }
set { _SampleRateChart = value; }
}
private int _CountRateBooks;
public virtual int CountRateBooks
{
get { return _CountRateBooks; }
set { _CountRateBooks = value; }
}
private int _CountRetailBooks;
public virtual int CountRetailBooks
{
get { return _CountRetailBooks; }
set { _CountRetailBooks = value; }
}
private Entities.Dealer _Dealer;
public virtual Dealer Dealer
{
get { return _Dealer; }
set { _Dealer = value; }
}
private Entities.ProductType _ProductType;
public virtual Entities.ProductType ProductType
{
get { return _ProductType; }
set { _ProductType = value; }
}
private List<Entities.RateChartRequestLoad> _RequestLoads;
[XmlArray("RequestLoads"), XmlArrayItem("RateChartRequestLoad", typeof(Entities.RateChartRequestLoad))]
public virtual List<Entities.RateChartRequestLoad> RequestLoads
{
get { return _RequestLoads; }
set { _RequestLoads = value; }
}
private List<RateChartRequestOptionItem> _RateChartRequestOptionItems;
[XmlArray("RateChartRequestOptionItems"), XmlArrayItem("RateChartRequestOptionItem", typeof(Entities.RateChartRequestOptionItem))]
public virtual List<RateChartRequestOptionItem> RateChartRequestOptionItems
{
get { return _RateChartRequestOptionItems; }
set { _RateChartRequestOptionItems = value; }
}
private Entities.Product _Product;
public virtual Entities.Product Product
{
get { return _Product; }
set { _Product = value; }
}
}
}
Mapping File:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="RateChart.DataAccess.Entities" assembly="RateChart.DataAccess">
<class name="RateChartRequest" table="t_RateChartRequest">
<id name="RateChartRequestID" type="Int32" unsaved-value="0">
<column name="RateChartRequestID" not-null="true" unique="true" index="PK_t_RateChartRequest" />
<generator class="native" />
</id>
<property name="EmailRateChart" column="EmailRateChart" type="Boolean" not-null="true"/>
<property name="PrintRateChart" column="PrintRateChart" type="Boolean" not-null="true"/>
<property name="SampleRateChart" column="SampleRateChart" type="Boolean" not-null="true"/>
<property name="CountRateBooks" column="CountRateBooks" type="Int32" not-null="true"/>
<property name="CountRetailBooks" column="CountRetailBooks" type="Int32" not-null="true"/>
<property name="RequestStatus" column="RequestStatus" type="String" not-null="true" />
<many-to-one name="Product" class="Product" column="ProductID" />
<many-to-one name="ProductType" class="ProductType" column="ProductTypeID" />
<bag name="RequestLoads" table="t_RateChartRequestLoad" cascade="all">
<key column="rateChartRequestID" />
<one-to-many class ="RateChartRequestLoad" />
</bag>
</class>
</hibernate-mapping>
|