Hi all,
I'm new to NH and yet have a complex (for me !) mapping problem.
I wanted to map a many to many relation with an extra information
column.
I did this mapping with a bag with a collection-type attribute set to
a custom object implementing IUserCollectionType. This bag is
embedding a composite-element.
All is working great when persisting or retrieving object !
I just have a problem using these objects in DetachedCriteria queries,
telling me there is no persister for the composite-element type.
I'll try to transpose my domain to a more common one, in order you can
well understand what I mean.
Imagine my app must deal with movies and actors. Each Movie object has
an Actors Collection. But I want to know who is the main actor
(without having a bool property in the Movie class).
So, in my BL I have :
public class Actor {
public virtual long Id {get;}
public virtual string Name{get; set;}
}
public class Movie {
public virtual long Id {get;}
public virtual string Title {get; set;}
public virtual IActorsCollection Actors {get; set;}
}
public interface IActorsCollection : ICollection<Actor>{
Actor Main {get; set;}
} [I have a concrete implementation of it (ActorCollection) to init
the collection on the creation of a Movie object.
I can then, use my objects this way : myMovie.Actors.Add(myActor);
myMovie.Actors.Main = myMainActor; etc. etc.
The DB (I can't modify) contains the table MovieActors as the relation
[bigint movie (PK), bigint actor (PK), bool isMainActor]
In my DAL, I have :
My mapping :
<bag name="Actors" lazy="true" table="MovieActors" generic="false"
access="field.camelcase" collection-type="DAL.MovieActorFactory, DAL"
>
<key column="Movie"/>
<composite-element class="DAL.MovieActor, DAL" >
<parent name="Movie"/>
<many-to-one name="Actor"
class="BL.Actor, BL"
column="Actor"
not-null="true"/>
<property name="IsMain" access="property" type="Boolean"
column="isMain" not-null="true" />
</composite-element>
</bag>
My associated code :
public class MovieActor {
public virtual Movie Movie {get; set;}
public virtual Actor Actor { get; set; }
public virtual bool isMain { get; set; }
}
public class MovieActorFactory : IUserCollectionType {...}
with custom transient and persistent collections:
public class TransientMovieActorCollection : IList<MovieActor>,
IActorsCollection
public class PersistentMovieActorCollection :
PersistentGenericBag<MovieActor>, IActorsCollection
Finally, my problem lies on call of query by criteria API functions. I
have the following error message : "No persister for : DAL.MovieActor"
So, my questions are the followings :
- Must I create another mapping for the MovieActor class (redundant
with the composite-element of the bag) ?
- Or better : Is there another (simpler ?) way to achieve this
mapping ? (Which one ? Working example/sample available ?)
I have been circling for weeks and now, I think I won't be able to
achieve this without your helpfull advices !
Thank you for having read this long post,
Looking forward to reading some answers !!
Sincerely,
Christophe
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---