I\'m building a Web API project that will be made available to third-party\'s and also used by my own web application/s. The Web API methods will return JSON representations
We can get really compact if we use AutoMapper.
Bootstrap the mapper in your repository:
Mapper.CreateMap
Then it's pretty simple (and there's nothing wrong with returning IEnumerable).
public IEnumerable Get()
{
using (var db = new MyContext())
{
return (from u in db.Users
orderby u.FirstName
select Mapper.Map(u)).AsEnumerable();
}
}