我有以下查询可行但速度太慢,因为它使用的是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