score:0

I think its because you are calling .FirstOrDefault(), which is only getting the first item. Can you omit that and add .ToList()? Also, var currentPokemon doesn't seem like a good variable name. You said you want a list of Encounters, right? How about var pokemonEncounters?

score:0

I think that the problem is the way that you set the relationship using ForeignKey and InverseProperty.

Try to rewrite to something like:

[Table("Pokemon")]
public class Pokemon
{
    public int Id { get; set; }
    public string Name { get; set; }

    [InverseProperty("Pokemon")]
    public ICollection<Encounter> Encounters { get; set; }

}

[Table("Enconters")]
public class Encounter
{
    public int Id { get; set; }

    public int PokemonId { get; set; }

    [ForeignKey("PokemonId")]
    public Pokemon Pokemon { get; set; }

}

score:0

My apologies, I've been looking to the wrong places for my answer. After stepping through this in a debugger, I can see that my Pokemon query does indeed return the desired result: A pokemon with many encounters attached. My problem seems to be elsewhere (specifically: the JSONified object I'm seeing come through to my web front-end truncates the encounters array to contain only the first result).

I'll post a new question with the correct problem and link to it from here when it's figured out.


Related Articles