I need to get the data from my database using a web api. Below is the code on how I implement it.
[HttpGet]
[Authorize]
[Route("api/getproperties")]
public async Task<List<Property>> GetProperties()
{
using(var db = new ApplicationDbContext())
{
var properties = await (from p in db.Properties
join pt in db.PropertyTypes
on p.PropertyTypeId equals pt.PropertyTypeId
select new
{
PropertyId = p.PropertyId,
PropertyName = p.PropertyName,
Owner = p.Owner,
Cluster = p.Cluster,
PropertyNumber = p.PropertyNumber,
RegionCode = p.RegionCode,
ProvinceCode = p.ProvinceCode,
MunicipalCode = p.MunicipalCode,
BarangayCode = p.BarangayCode,
DateAdded = p.DateAdded,
DateModified = p.DateModified,
PropertyTypeId = p.PropertyTypeId,
PropertyType = p.PropertyType,
Type = pt.Type
}
).ToList()
.Select(x => new Property
{
PropertyId = x.PropertyId,
PropertyName = x.PropertyName,
Owner = x.Owner,
Cluster = x.Cluster,
PropertyNumber = x.PropertyNumber,
RegionCode = x.RegionCode,
ProvinceCode = x.ProvinceCode,
MunicipalCode = x.MunicipalCode,
BarangayCode = x.BarangayCode,
DateAdded = x.DateAdded,
DateModified = x.DateModified,
PropertyTypeId = x.PropertyTypeId,
PropertyType = x.PropertyType,
Type = x.Type
}).ToListAsync();
return properties;
}
}
If I do not use the "async Task>" and remove the ".ToListAsync()" and "await" at the beginning, I do not get the errors. But with it, the function is not going to be Asynchronous anymore. Can you please show me how to this right? Thank you.
Select?