Nhibernate: left outer join in subquery

Update 2

Here are two queries I'm working with (paging is omitted in both queries)

I would like to receive the following request

SELECT * 
FROM product
LEFT OUTER JOIN 
(
    SELECT * 
    FROM Cart 
    LEFT OUTER JOIN 
    cartproducts 
    ON Cart.Id = cartproducts.Cart_id 
    WHERE Cart.username = 'user'
)
AS CartFiltered 
ON product.Id = CartFiltered.product_id

but i always get

SELECT * 
FROM product  
LEFT OUTER JOIN 
cartproducts 
ON product.Id = cartproducts.Product_id 
LEFT OUTER JOIN
Cart
ON
cartproducts.cart_id = cart.id
WHERE Cart.username = 'user'

How do I create the first request? I hope my question is clearer :) Lack of clarity is sometimes my biggest enemy: p


Update:

FWIW, I still haven't found the answer, and I'm currently loading the paginated product data and the entire cart to display the correct object. A raw solution, but it works, and it surpasses the combinatorial elements that I came across, trying to get the Criteria API to recognize me as its master. I would be very interested if anyone could accidentally point me in the right direction;)


Hello,

API , , : , .

. ( ), , . , , . , NHibernate , .

Dim critPage As ICriteria = Session.CreateCriteria(GetType(Product)) _
.SetFirstResult(pageNumber * itemsPerPage).SetMaxResults(itemsPerPage) _
.CreateCriteria("Carts", "c", SqlCommand.JoinType.LeftOuterJoin) _
.SetProjection(plist) _ 
.SetResultTransformer(New TypedResultTransformer(Of ProductWithCartInfo)) _
.Add(Expression.Eq("c.User", username))

, , ProductWithCartInfo. .

, , , .

API- Nhibernate? API , .

+3
1

, , , . , () criteira NHibernate, . , criteira.

, ...

criteria.CreateAlias("Cart", "Cart", JoinType.LeftOuterJoin);

ICriterion cartCriterion = Restrictions.Eq("Cart.User", username);
customerCriterion = Restrictions.Or(customerCriterion, Restrictions.IsNull("Cart.User"));
criteria.Add(customerCriterion);

, ... ... , SQL, , .

+6

Source: https://habr.com/ru/post/1713633/


All Articles