Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting a collection of related entities in the correct way in EF4 using POCO's (src is the DB)
    text
    copied!<p>I have a POCO entity <code>Report</code> with a collection of a related POCO entity <code>Reference</code>. When creating a <code>Report</code> I get an <code>ICollection&lt;int&gt;</code> of ids. I use this collection to query the reference repository to get an <code>ICollection&lt;Reference&gt;</code> like so:</p> <pre><code>from r in referencesRepository.References where viewModel.ReferenceIds.Contains(r.Id) select r </code></pre> <p>I would like to connect the collection straight to <code>Report</code> like so:</p> <pre><code>report.References = from r in referencesRepository.References where viewModel.ReferenceIds.Contains(r.Id) select r; </code></pre> <p>This doesn't work because <code>References</code> is an <code>ICollection</code> and the result is an <code>IEnumerable</code>. I can do <code>ToList()</code>, but I think I will then load all of the references into memory. There also is no <code>AddRange()</code> function.</p> <p>I would like to be able to do this without loading them into memory.</p> <p>My question is very similar to <a href="https://stackoverflow.com/questions/3203744/best-strategy-for-adding-or-updating-a-collection-of-related-entities-when-using">this</a> one. There, the only solution was to loop through the items and add them one by one. Except in this question the list of references does not come from the database (which seemed to matter). In my case, the collection <em>does</em> come from the database. So I hope that it is somehow possible.</p> <p>Thanks in advance.</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