I have a WebAPI method that returns an IQueryable of a 'complex' object in the following format:
[Route("api/INV_API/deptSelect")]
public IQueryable<DEPTNAME_DESCR> GetDistinctDeptSelect([FromUri] string q)
{
if (q != null)
{
var query = (from d in db.DEPTs
where d.DESCR.Contains(q) || d.DEPTNAME.Contains(q)
select new DEPTNAME_DESCR { DEPTNAME = d.DEPTNAME, DESCR = d.DESCR }).Distinct();
return query;
}
else
{
var query = (from d in db.DEPTs
select new DEPTNAME_DESCR { DEPTNAME = d.DEPTNAME, DESCR = d.DESCR }).Distinct();
return query;
}
}
When I use AJAX to make a GET request to this method, I receive a JavaScript array response like this:
https://i.sstatic.net/h17EA.png
In another WebAPI method, I am attempting to return an IQueryable<string> from what was originally a List of strings:
[HttpGet]
[Route("api/INV_API/requesterIdSelect2")]
public IQueryable<string> GetListOfUserId([FromUri] string q)
{
var result = db.Database.SqlQuery<string>("SelectUSERIDFromSM @searchterm", new SqlParameter("@searchterm", q)).ToList();
return result.AsQueryable<string>();
}
However, when I inspect the response from the AJAX GET request, it appears like this: https://i.sstatic.net/UeF1B.png
I'm trying to figure out what went wrong with the second method. Do I need to serialize the data I'm returning? Or is there something incorrect with my SQL query itself?
I can provide more details if needed.