I have an entity object called Patient , and this object has a property called Visits , which is of type VisitsCollection .
VisitsCollections is a child of IList<Visit> , but it also adds some user logic to the collection (for example, automatic ordering, some checks, notifications, etc.).
I need to use a custom collection type as it adds some data to objects that are added to the collection and transparently executes some other documents.
Now I want to display this in NHibernate, so I created:
<list name="Visits" lazy="true" fetch="select"> <key foreign-key="PatientId" /> <index column="Timestamp" /> <one-to-many class="Visit" not-found="ignore"/> </list>
I get an exception:
Cannot apply an object of type "NHibernate.Collection.PersistentList" to type "... VisitsCollection"
Whenever I access the visits property.
I also tried to display it like this:
<list name="Visits" lazy="true" fetch="select" collection-type="VisitsCollection"> <key foreign-key="PatientId" /> <index column="Timestamp" /> <one-to-many class="Visit" not-found="ignore"/> </list>
but still I get this exception:
User type does not implement UserCollectionType: ..... VisitsCollection
I don’t want to inherit my VisitsCollection from any type of NHibernate, because the collection class is part of the structure in which I want it to be a DAL agnostic (since it will be used in many scenarios - not just using the database).
Any ideas on how to map this while maintaining the structure of my code?
Thanks in advance.
collections nhibernate nhibernate-mapping
Karim agha
source share