Make and AJAX call from the client to your static method:
$.ajax({
type: "POST",
url: "/WebMethods/Test.aspx/getChildren",
data: "{myID:" + someID+ "}",
contentType: "application/json",
dataType: "json",
success: function (msg) {
// work on your json
},
error: function (msg) {
alert("error:" + JSON.stringify(msg));
}
});
Find your parent entity using a parameter, then you can find all children entities that belong to that parent. Make sure your foreign key constraints are established in your entity model.
public static string getChildren(int myID){
using (var rep = new context()) {
Header head = rep.Headers.Where(x => x.ID== myID).First();
var details = head.Details.ToList();
}
// Convert List to JSON and return to client
string myChidren="";
return myChildren;
}