I've got a GET entry point on UsersController
. But this one is responding an array of empty objects. When I debug the entry point, the list (IEnumerable<UserViewModel>
) is not empty and UserViewModels
are not empty either.
But here is what it does respond:
[{},{},{},{},{},{},{},{},{},{},{},{}]
And the controller code:
[HttpGet]
public async Task<IEnumerable<UserViewModel>> Get()
{
var u = _stObjMap.Default.Obtain<UserTable>();
using (var ctx = new SqlStandardCallContext())
{
var a = await ctx[u].Connection.QueryAsync<UserViewModel>("SELECT UserId, UserName, PrimaryEMail, CreationDate from CK.vUser where UserId <> 0 and UserId <> 1");
return a;
}
}
I really don't think that the problem is coming from the controller. I'm using Dapper.I really don't know what is happening. And I have to write a lot because I can't edit this post
Most likely the UserViewModel
has no public properties defined.
Which is why no key value pairs are displayed when the object is serialized to JSON.
Based on the query, make sure there are matching properties in the model for the Dapper query to map the selected columns
public class UserViewModel
public int UserId { get; set; }
public string UserName { get; set; }
public string PrimaryEMail { get; set; }
public DateTime CreationDate { get; set; }
}