I have 2 classes such as Trail and National park as shown below having one to many relationship for ex one NationalPark can have many Trails
public class Trail
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public double Distance { get; set; }
public enum DifficultyType { Easy, Moderate, Difficult, Expert}
public DifficultyType Difficulty { get; set; }
[Required]
public int NationalParkId { get; set; }
[ForeignKey("NationalParkId")]
public NationalPark NationalPark { get; set; }
public DateTime DateCreated { get; set; }
}
public class NationalPark
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string State { get; set; }
public DateTime Created { get; set; }
public byte[] Picture { get; set; }
public DateTime Established { get; set; }
}
By using the below code I am getting every field in NationalPark class as shown below
public Trail GetTrail(int trailId)
{
return _db.Trails.Include(c => c.NationalPark).FirstOrDefault(a => a.Id == trailId);
}
this is the result
[
{
"id": 1,
"name": "Trail1,Np3",
"distance": 114,
"difficulty": 2,
"nationalParkId": 3,
"nationalPark": {
"id": 3,
"name": "Test2",
"state": "MP",
"created": "2008-10-11T13:23:44",
"picture": null,
"established": "2002-10-11T13:23:44"
}
]
I wanted to avoid the "picture" field in the above result, please help Thanks in Advance