Model:
public class Word
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime? WhenCreated { get; set; }
public ApplicationUser Author { get; set; }
[NotMapped]
public string AuthorName
{
get
{
if (Author != null)
{
return Author.UserName;
}
else {
return "";
}
}
}
public List<Definition> Definitions { get; set; }
}
Controller:
[HttpGet]
public IEnumerable<Word> Get()
{
return _db.Words.Include(x=>x.Author).ToList();
}
Now My Controller returns the entire class ApplicationUser, which is one of the properties Word. I want to send only one property ApplicationUser: UserName. How can i do this?
I added AuthorNamethat will only return the data that I want from ApplicationUser. Unfortunately, I still need .Include(x=>x.Author)this property to work. Can I somehow omit, including Authorduring data serialization (to hide it when sending data to the user)?
, .Select(), . , .Select(), .
?