Developer forum

Forum » Development » Error in Order.GetOrders(sql, true)

Error in Order.GetOrders(sql, true)

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

When I call Order.GetOrders(sql, true) and the SQL statement doesn't result in any orders being returned, the method crashes with an "Incorrect syntax near ')'" error message. It looks like the code to retrieve the order lines runs regardless of whether any orders were found which then leads to issues when building up the WHERE clause.

I can work around it with code like this:

      const string sql = "SELECT * FROM EcomOrders WHERE (OrderCart = 0)";
      var hasOrders = Order.GetOrders(sql, false).Any();
      if (hasOrders)
      {
        var orders = Order.GetOrders(sql, true);
        // process orders here.
      }

 

but that feels kind of silly.

Are there other ways to retrieve orders and order lines that doesn't crash when no orders match the SQL statement?

Thanks,

Imar

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Imar

As you already do, you do not have to call the GetOrders with the Preload orderlines parameter set to true.

That means that the Order.Orderlines property will not load the orderlines before you access the property, aka lazy loading. That is not an issue unless you have a lot of orders. So that would be the work around.

I've created and fixed the bug for 8.6, TFS#16338, that will skip the orderline loading if no orders are found.

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Great, thanks. This is code for an order export so eager loading is preferred.

 

Imar

 

You must be logged in to post in the forum