我需要将 sql 查询的结果返回到我的移动应用程序。
我有一个关于 azure 和移动服务的数据库。
我在我的服务中添加了一个新的自定义 API 控制器,但我无法取回任何记录。我一直在阅读和阅读,但仍然不明白我错过了什么。任何帮助将不胜感激
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Microsoft.WindowsAzure.Mobile.Service;
using mytestService.Models;
using mytestService.DataObjects;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;
using System.Threading.Tasks;
namespace mytestService.Controllers
{
public class SelectMapMarkersController : ApiController
{
public ApiServices Services { get; set; }
public class MapMarkers
{
public string MerchantName { get; set; }
public double MerchantLongitude { get; set; }
public double MerchantLatitude { get; set; }
public string MerchantMiniURL { get; set; }
public string Deal { get; set; }
public string CategoryDescription { get; set; }
}
// GET api/SelectMapMarkers
public List<MapMarkers> Get()
{
using (mytestContext context = new mytestContext())
{
// Get the database from the context.
var database = context.Database;
string sql = "select MerchantName, MerchantLongitude, MerchantLatitude, MerchantMiniUrl, Deal, CategoryDescription from mytest.tblMerchants m inner join mytest.tblMerchantDeals d on d.merchantId = m.merchantid inner join mytest.tblMerchantCategories mc on mc.merchantid = m.merchantid inner join mytest.tblCategories c on c.categoryid = mc.categoryid where m.MerchantActive = 1 and (d.dealstartdate <= getdate() and d.dealenddate >= getdate()) ";
List<MapMarkers> result = database.SqlQuery<MapMarkers>(sql).ToList<MapMarkers>();
return result;
}
}
}
}