我创建了一个webAPI控制器方法,它看起来如下:
[HttpGet]
public HttpResponseMessage RealEstates()
{
using (BoligsideDbContext context = new BoligsideDbContext())
{
List<RealEstateVm> realEstateVms = context.RealEstates.OrderByDescending(x => x.Id).ToList().Select(x => new RealEstateVm(x)).ToList();
return Request.CreateResponse(HttpStatusCode.OK, realEstateVms);
}
}
Run Code Online (Sandbox Code Playgroud)
我的VM看起来如下:
public class RealEstateVm
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Area { get; set; }
public int Rooms { get; set; }
public int Rent { get; set; }
public string Picture { get; set; …Run Code Online (Sandbox Code Playgroud)