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.
Source: stackoverflow.com
Related Articles
- EF6 Linq Query .Include only returning first entry of child table
- LINQ query to include fields from one row of a child table
- Linq query only returning first item of array
- Linq query selects values from first row only in table
- LINQ Query Returning Multiple Copies Of First Result
- Linq query for only the first N rows for each unique ID
- Linq query and multiple where clauses with OR only first condition gets evaluated
- My LINQ Query is Returning only 1 result
- C# Automapper IQueryable - LINQ 2 SQLite - Query returns only parent, nested child always null
- Linq sub query when using a repository pattern with EF code first
- is there a better way to write this frankenstein LINQ query that searches for values in a child table and orders them by relevance?
- How to include a table multiple times in Linq query
- Make access possible to dynamic table LINQ EF6 Code First
- Code First EF 6 Table Per Hierarchy SQL query generation issue
- Why this linq query returns only first attribute?
- how to write a Linq query with a EF code first Many to Many relationship
- Load parent and child table in one query linq to entitiy
- Include null cells in Linq query from DB in C# code
- Linq query to Join tables if value not in first table fetch from second
- Include unrelated table in Linq to entity query
- Linq Query modification to include a value in a related table
- Linq query to join two tables and return object from first table - PagedList used
- LINQ to XML query returning a list of all child elements
- How to project a Mongo LINQ query to only return child object from document?
- Cassandra C# driver: Linq table queries returning data from first keyspace after changing keyspace on session
- Linq query on XML only returns first element
- How to LINQ Query Code First generated EF6 hierarchical entities (entities within entities)?
- How do I write a where query to only include 1 entity of child
- C# LINQ query to select only first date in a month from List<DateTime>
- Why does a Linq query on XML file checks only the first parameter of many?
- Converting complex sql stored proc into linq
- How linq-to-nhibernate between 2 lists by StartsWith
- How to create a combobox into a dgv using entity framework and linq
- ASP.NET Deserialize JSON with LINQ and loop through results
- Creating a @Html.DropdownList for from several db columns
- Best way of concatenating one value of objects by comma separation? C#
- When I'm trying to bring one value from a table with email, the result is always null
- Linq query to return results when an ICollection is empty.
- LINQ XML - Select all parent elements where a child has a given value
- Is there an alternative to LINQ let operator that doesn't hit performance?
- Linq SubmitChanges does not work
- Why does Enumerable<T>.ToArray() use an intermediary Buffer when it can just call Count() first?
- LINQ indexOf a particular entry
- When to use lambda expressions instead of a Where clause in LINQ
- Resharper, linq within foreach loop
- EF Core - LINQ - Assign property to IQueryable<T>
- LINQ to SQL and the the order of Take() and Skip()
- LINQ find first occurrence before and after target value of equal distance
- Returning recursive result
- Returning Linq value in controller and passing it to View