I have this simple controller in a NetCore 2 Entity Framework API app that is supposed to get a list of nationalparks based on the stateID:
[HttpGet("ListNationalParksByState/{stateId}")]
public async Task<ActionResult<IEnumerable<NationalParkList>>> GetNationalParksForState(Guid stateID)
{
var nationalparkList = await _context.NationalParkList.Where(n => n.StateId == stateID).ToListAsync();
return nationalparkList;
}
But my returned JSON only shows this:
[{"state":{"nationalparkList":[
However, when I set a breakpoint in that controller, it shows it found 3 nationalparks (I'm not sure was Castle.Proxies is):
[0] {Castle.Proxies.NationalParkListProxy}
[1] {Castle.Proxies.NationalParkListProxy}
[2] {Castle.Proxies.NationalParkListProxy}
Expanding those shows the 3 nationalparks and all their properties.
Here is my NationalParkList model:
public partial class NationalParkList
{
public NationalParkList()
{
NationalParkLinks = new HashSet<NationalParkLinks>();
}
public string NationalParkId { get; set; }
public Guid StateId { get; set; }
public string NationalParkTitle { get; set; }
public string NationalParkText { get; set; }
public virtual StateList State { get; set; }
public virtual ICollection<NationalParkLinks> NationalParkLinks { get; set; }
}
Here is how it's defined in my dbcontext:
modelBuilder.Entity<NationalParkList>(entity =>
{
entity.HasKey(e => e.NationalParkId)
.HasName("PK_NationalParkList");
entity.ToTable("nationalparkList");
entity.Property(e => e.NationalParkId)
.HasColumnName("nationalparkID")
.HasMaxLength(50)
.ValueGeneratedNever();
entity.Property(e => e.StateId).HasColumnName("stateID");
entity.Property(e => e.NationalParkText).HasColumnName("nationalparkText");
entity.Property(e => e.NationalParkTitle)
.HasColumnName("nationalparkTitle")
.HasMaxLength(3000);
entity.HasOne(d => d.State)
.WithMany(p => p.NationalParkList)
.HasForeignKey(d => d.StateId)
.HasConstraintName("FK_nationalparkList_stateList");
});
I'm not getting any errors, I'm just not getting any data.
Does anyone see why I'd get no data when I hit this controller?
Thanks!