NHibernate Collections problem (check your mapping file for property type inconsistencies)

I get the following error: Unable to pass an object of type "NHibernate.Collection.Generic.PersistentGenericSet" to enter "Iesi.Collections.Generic.SortedSet.

Invalid mapping information specified for type [Type], check the mapping file for property type mismatches. "

Here is my set definition:

<set name="ProcessTrackerDetails" lazy="true" access="field.camelcase-underscore" 
                sort="natural" cascade="all" inverse="true">
  <key column="ProcessTrackerDetailsID"/>
  <one-to-many class="ProcessTrackerDetail"></one-to-many>
</set>

And here is the code:

private Iesi.Collections.Generic.SortedSet<ProcessTrackerDetail> _processTrackerDetails = new SortedSet<ProcessTrackerDetail>();

Suggestions?

+3
source share
3 answers

NHibernate requires interfaces. Try using ISet<ProcessTrackerDetail>insteadSortedSet<ProcessTrackerDetail>

+10
source

Modify your code to define _processTrackerDetails using the ISet interface.

private ISet<ProcessTrackerDetail> _processTrackerDetails = 
    new SortedSet<ProcessTrackerDetail>();

SortedSet, , , , NHibernate ISet . = "" .

+2

"" ( , NHibernate.Collection.Generic.PersistentGenericSet), System.Collections.Generic.ICollection System.Collections.Generic.HashSet.

Castle ActiveRecord, , :

// In the Collections entity mapping
    [HasAndBelongsToMany(typeof(Region),
    Table = "CollectionRegionAssociation", ColumnKey = "CollectionId", ColumnRef = "RegionId", RelationType = RelationType.Set)]
    public virtual System.Collections.Generic.ICollection<Region> Regions { get; set; }

// Creating and saving a new object
    var c = new Collection(); // my own entity
    c.Regions = new System.Collections.Generic.HashSet<Region>();
    c.Regions.Add(new Region() { ... });
    c.Save();
0

Source: https://habr.com/ru/post/1719049/


All Articles