I have the following method. Which returns “Could not execute update query”. If i query another entities property ie “Order.Campaign.Id” do i need include a join? How would this work. ?
public void RemoveOrderItems(int companyId, int campaignId, int productId, int orderStatus)
{
using (ITransaction transaction = _session.BeginTransaction())
{
_session.CreateQuery("delete from OrderItem where Product.Id = '" + productId + "' and Order.Company.Id = '" + companyId + "' and Order.Campaign.Id = '" + campaignId + "' and Order.OrderStatus = '" + orderStatus + "'").ExecuteUpdate();
transaction.Commit();
}
}
** EDIT **
Here is the sql statement.
DELETE oi
FROM OrderItems oi inner JOIN Orders o On oi.OrderId = o.Id
Where oi.ProductId = '13077' and o.CompanyId = '32' and o.CampaignId = '2' and o.OrderStatus = 3
The generated SQL is not exactly the same that you created manually, but it’s semantically equivalent.