I need to deliver a JSON that has a TimelineItem where each timelineitem corresponds to a user.
User class
public class User
{
public int Id { get; set; }
public string Name { get; set; }
}
Class timelineitem
public class TimelineItem
{
public int Id { get; set; }
public string Content { get; set; }
public string Title { get; set; }
public User User { get; set; }
}
My get in the api
// GET: api/TimelineItems
[HttpGet]
public IEnumerable<TimelineItem> GetTimelineItems()
{
return _context.TimelineItems;
}
JSON who gives me
[{"id":2,"content":"fsdaj fdsfa fsdjklafjlk fdjsaklfjsad fjdsklf fdsjakl","title":"fjdskjfsdakl","user":null},{"id":3,"content":"fsdjk wqeui ietuw q tweti gj vcm v,cmv vmc,v c","title":"ureiwu","user":null},{"id":4,"content":"hola amigos del yu tub","title":"fdsfsda","user":null}]
All users return null.
I suppose I should change the TimelineItem model?