Note that there are some explanatory texts on larger screens.

plurals
  1. POFiltering inner collection with Entity Framework 5 and Repository pattern and Unit of Work
    text
    copied!<p>I'm using the Repository and Unit Of Work Pattern with Entity Framework 5</p> <p>I want to get all the "Agencies" with its "Cars" but only those Cars that have an id in the list sent by parameter and that belongs to the state sent by parameter.</p> <p>For example</p> <pre><code>public IEnumerable&lt;Agency&gt; GetList(int stateId, string idCarList) var ids = idTiposTarjetasList.Split(','); var intIds = ids.Select(int.Parse); </code></pre> <p>Then I have </p> <pre><code>Uow.Agencies.GetAll() </code></pre> <p>and</p> <pre><code>Uow.Agencies.GetAllIncluding(a =&gt; a.Cars) </code></pre> <p>which retrieves an IQueryable&lt; T ></p> <p>Is there anyway I can retrieve in one query the Agencies containing its Cars but only those that have an id contained in the intIds list and stateId matching stateId parameter?</p> <p>I've already seen this <a href="https://stackoverflow.com/questions/3981417/how-to-sort-inner-list-that-is-returned-by-entity-framework">Stackoverflow question</a>, but the retrieval of the IQueryable is getting me troubles to get it work.</p> <p>If I write this var sortedList = from x in Uow.Agencies.GetAllIncluding(c => c.Cars) then the select can't be done (says arguments cannot be inferred from the query</p> <p>This doesn't work:</p> <pre><code>var ids = idCars.Split(','); var intIds = ids.Select(int.Parse); var agencies = from agency in Uow.Agencies.GetAllIncluding(c =&gt; c.Cars).Where(c =&gt; intIds.Contains(c.Cars.Id)).OrderBy(s =&gt; s.Id) select agency; if (agencies.Any()) { return agencies; } </code></pre> <p>How can I do it? Thanks! Guillermo.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload