One list. No "where"

    Diego


On Thu, Aug 26, 2010 at 14:26, Mark Wilkins <[email protected]> wrote:

> ah, OK.
>
> Yes, I sort of thought that I might be doing something unholy. Thanks.
>
> I will map it as it is in the DB. Would it also make sense to have to
> separate lists such as:
>
> <list name="FavoriteKittens" ... where="Rank=1">
> ...
> </list>
>
> <list name="SecondFavoriteKittens" ... where="Rank=2">
> ...
> </list>
>
> and project them as
>
> public FavoriteKitten { get { return FavoriteKittens[0]; } }
> public SecondFavoriteKitten { get { return SecondFavoriteKittens[0]; } }
>
> Thanks again.
>
> On Thu, Aug 26, 2010 at 1:19 PM, Diego Mijelshon <[email protected]>
> wrote:
> > The whole structure is wrong. A one-to-one relationship can't depend on a
> > criteria query.
> > Put another way, you must either make it work with just the mapping (I
> don't
> > think it's possible), so session.Get<Cat>(id) returns everything
> correctly,
> > or do it all in a query, without mapping the relationship.
> > An alternative is mapping it as it really is in the DB: a List. Then you
> can
> > project the properties in the class:
> > public FavoriteKitten { get { return FavoriteKittens[0]; } }
> > public SecondFavoriteKitten { get { return FavoriteKittens[1]; } }
> >
> >     Diego
> >
> >
> > On Thu, Aug 26, 2010 at 13:28, Mark Wilkins <[email protected]>
> wrote:
> >>
> >> Let's say I have a Cat that has two properties: FavoriteKitten,
> >> SecondFavoriteKitten. These kittens are discriminated by their Rank.
> >> When loading a Cat, I want the kitten with the rank of "1" to be
> >> FavoriteKitten, and the kitten with the rank of "2" to be
> >> SecondFavoriteKitten.
> >>
> >> The underlying database looks like:
> >> table Cat
> >> ----------------
> >> CatId
> >>
> >> table Kitten
> >> -----------------
> >> KittenId
> >> CatId
> >> Rank
> >>
> >> My mapping looks like:
> >> <class name="Cat">
> >>        ... other stuff
> >>                <one-to-one name="FavoriteKitten" class="Kitten"
> >> property-ref="Cat"
> >> cascade="all-delete-orphan" />
> >>                <one-to-one name="SecondFavoriteKitten" class="Kitten"
> >> property-ref="Cat" cascade="all-delete-orphan" />
> >> </class>
> >>
> >> My criteria query looks like
> >> Cat cat = sess.CreateCriteria(typeof(Cat))
> >>    .CreateAlias("FavoriteKitten", "kt1")
> >>                .Add(Expression.Eq("kt1.Rank", "1"))
> >>    .CreateAlias("SecondFavoriteKitten", "kt2")
> >>                .Add(Expression.Eq("kt2.Rank", "2"))
> >>    .UniqueResult();
> >>
> >> The trouble is that once loaded, both FavoriteKitten and
> >> SecondFavoriteKitten are the same kitten; the one with a Rank of "2".
> >>
> >> Have I left something out of the criteria? Or am I going about this
> >> the wrong way?
> >>
> >> Thanks,
> >>
> >> Mark
> >>
> >> --
> >> 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]<nhusers%[email protected]>
> .
> >> For more options, visit this group at
> >> http://groups.google.com/group/nhusers?hl=en.
> >>
> >
> > --
> > 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]<nhusers%[email protected]>
> .
> > For more options, visit this group at
> > http://groups.google.com/group/nhusers?hl=en.
> >
>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

-- 
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.

Reply via email to