I have 2 classes:
first one - "ConstructionElement", here's the mapping:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Entities" namespace="Entities.Business">
<class name="ConstructionElement" table="CNSTR_ELEM">
<id name="Id" column="ID" type="Int64">
<generator class="sequence">
<param name="sequence">CNSTR_ELEM_SEQ</param>
</generator>
</id>
<component name="MaterialDescription"
class="Entities.Base.MultiNameEntity">
<bag name="NamesI" table="CNSTR_ELEM_CD" lazy="false"
cascade="all">
<key column="PARENT_ID"/>
<composite-element
class="Entities.Localization.LocalizedString, Entities">
<property column="CULTURE_ID" name="Language"
type="Common.Enums.RequestedLanguage, Common"/>
<property column="TEXT" name="Value" type="System.String"/>
</composite-element>
</bag>
</component>
</class>
</hibernate-mapping>
second - MultiNameEntity:
public class MultiNameEntity
{
private ObservableCollection<LocalizedString> _names;
private IList<LocalizedString> _namesI;
protected virtual IList<LocalizedString> NamesI
{
get
{
if (_names != null)
return _names;
return _namesI;
}
set { _namesI = value; }
}
public virtual ObservableCollection<LocalizedString> Names
{
get
{
if (_names == null)
{
if (_namesI != null &&
NHibernateUtils.IsInitialized(_namesI))
{
_names = new
ObservableCollection<LocalizedString>();
_names.AddRange(_namesI);
}
}
return _names;
}
set { _names = value; }
}
}
When I'm trying to save instance of ConstructionElement, following
exception occurs:
Unable to cast object of type
'System.Collections.ObjectModel.ObservableCollection`1[Entities.Localization.LocalizedString]'
to type 'NHibernate.Collection.IPersistentCollection'.
If I'm bringing <bag> mapping out of <component> tag, then save\update
works fine.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.