i'm getting a key not found error on
tempCustQuery.GetExecutableCriteria(session)

i'm using this as a guide:
http://ayende.com/blog/1900/complex-searching-querying-with-nhibernate

I'm trying to get all customers that have a child with the given 2 column
values.

    // temp customer query
    var tempCustQuery =
DetachedCriteria.For<TechSupportCustomer>("tempCusts")
        .Add(nhc.Expression.IsNull("BillingInstanceID"))
        .Add(nhc.Expression.Sql("({alias}.SAVED_ACCOUNT_ID is null)"))
        .SetResultTransformer(new
NHibernate.Transform.DistinctRootEntityResultTransformer());

    // create the subquery for the antn matches
    var antnMatchQuery = DetachedCriteria.For<TechSupportCustomerAnTn>()
        .Add(Restrictions.Eq("TelephoneNumber", dslPhone))
        .Add(Restrictions.Eq("AccountNumber", billingPhone))
        .SetProjection(Projections.Id()) // only query/hydrate the ID in the
final query
        .Add(Property.ForName("ID").EqProperty("antns.ID"));

    // add the subquery to the customer query
    tempCustQuery.CreateCriteria("ANsTNs", "antns")
        .Add(Subqueries.Exists(antnMatchQuery));

   // get resulting customer entities
    var results = tempCustQuery.GetExecutableCriteria(session)
        .List<TechSupportCustomer>();

in SQL:

select * from customers c
where BILLING_ID is null and SAVED_ID is null
and exists ( select 1 from customers_antns antns
                  where antns.cust_id = c.id
                  and antns.TN = <value> and antns.AN = <value>)

what am I doing wrong?
(and at this point, why shouldn't I just do it with Expression.Sql??)

------
Joe Brockhaus
[email protected]
------------

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