Skip to content
Advertisement

Only returning one record in dataset

I am using ado .net in my web API and dapper and I have a function that checks the orders and the order lines it works fine if their only one order but if there an order without order lines it won’t display the order details.

Class For Delivery Items

Class for Delivery Lines.

I need the above routine to work in a way that if the order has no order lines it will still display the top order header details. I presume I am missing something in my sql as this should be easy.

For at the min my app is showing the following.

When it should be showing the two records that is here in the data.

enter image description here

Advertisement

Answer

The problem is in your SQL. An INNER JOIN requires a match. In this case that match is between Deliverys.id and DeliveryLines.DeliveryId according to your ON clause.

Use a LEFT JOIN if you want to include deliveries in your results even if a delivery has no delivery lines. Also, be prepared for your delivery lines fields to come back NULL, which is what to expect for those columns when no row exists in the LEFT JOIN match attempt.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement