I found this question that is similar to what I'm asking, but not exactly the same: Is there some way I can "join" the contents of two javascript arrays much like I would do a join in SQL
In that question, the user provides two arrays that they want to join in an SQL-like manner.
My difference is that I have several APIs set up to reference a database. I need to get the APIs to "join" on a value.
Here's a rough sample of the classes:
public partial class test_review
{
[Key]
public int rating_id { get; set; }
public int site_id { get; set; }
public string comments { get; set; }
}
and:
public partial class test_site
{
[Key]
public int site_id { get; set; }
[Required]
[StringLength(3)]
public string site_name { get; set; }
}
If I was writing this in SQL, I would do something like
SELECT r.rating_id, s.site_name, r.comments
FROM test_review r
INNER JOIN test_site s on r.site_id = s.site_id
Currently, I have code that looks like this in my ReadReviews.aspx page:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
function getReviews() {
$.getJSON("api/review",
function (data) {
$('#reviews').empty();
$.each(data, function (key, val) {
var row = '<td>' + val.rating_id + '</td><td>' + val.airport_id + '</td>';
$('<tr/>', { html: row })
.appendTo($('#reviews'));
});
});
}
$(document).ready(getReviews);
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h2> Here are the API reviews</h2>
<table>
<thead>
<tr>
<th>Rating_id</th>
<th>airport_id</th>
</tr>
</thead>
<tbody id ="reviews">
</tbody>
</table>
</asp:Content>
(Note: this jquery code came from https://learn.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/using-web-api-with-aspnet-web-forms)
This is great and all, but not exactly what I'm looking for in this case. I need to combine information from the two APIs.
Would it have been better to create a few views? I know that I CAN do that, but I'm not sure that it's better/more efficient/faster than pulling directly from the tables and combining them somehow.