我有以下有效的查询,但它太慢了,因为它正在使用 IN:
_session.CreateQuery(@"
delete OrderItem oi
where oi in
(select i
from OrderItem i
where i.Product.Id = :productId
and i.Order.Company.Id = :companyId
and i.Order.Campaign.Id :campaignId
and i.Order.OrderStatus = :orderStatus)
")
.SetParameter("productId", productId)
.SetParameter("companyId", companyId)
.SetParameter("campaignId", campaignId)
.SetParameter("orderStatus", orderStatus)
.ExecuteUpdate();
有没有一种方法可以使用本机查询,您可以简单地使用连接进行删除,例如:
DELETE posts
FROM posts
INNER JOIN projects ON projects.project_id = posts.project_id
WHERE projects.client_id = :client_id