In short when I create an ICriteria on an interface type association
with a DetachedCriteria, the detached query (being a child of the
parent interface) generates sql where the foreign key of the child
binds to the discriminator of the parent rather than its id.

Parent-Child mapping (notice the parent Account is an interface):
<class name="IAccount" table="Account">

                <id name="Id" column="Id" type="int" >
                        <generator class="native">
                        </generator>
                </id>

                <discriminator column="AccountTypeId"></discriminator>

                <set name="AddressList" table="AccountAddress" cascade="all"
lazy="true" inverse="true" >
                        <key column="AccountId" />
                        <one-to-many class="AccountAddress" />
                </set>
...

Query:
ICriteria criteria = MakeCriteria("a")                  //custom
Criteria generator a is alais for IAccount

DetachedCriteria addressQuery = DetachedCriteria.For(typeof
(AccountAddress), "al");
addressQuery
                    .Add(Restrictions.Like("al.City", 'Lodon',
MatchMode.Anywhere))
                    .Add(Restrictions.EqProperty("al.Account",
"a.class"))                 //a.Class is the interface parent
                    .SetProjection(Projections.Property
("al.Account"));
                criteria.Add(Subqueries.PropertyIn("a.class",
addressQuery));

I want all the accounts that have a Lodon address. I also want the
accounts distinctly which also does not seem to work when I use
DistinctRootEntityResultTransformer but that is another issue (see a
piece of my mapping for this below:

IAccount criteria:
...
                .AddOrder(new Order(sortIdx, string.Compare(sortOrder,
"ASC", true) == 0))
                .SetResultTransformer(new
DistinctRootEntityResultTransformer())
                .SetResultTransformer(
                new AliasToBeanConstructorResultTransformer(
                    typeof (AccountDTO).GetConstructor(new Type[]
                                                           {
                                                               typeof
(string),
...

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