I have a POCO entity Report
with a collection of a related POCO entity Reference
. When creating a Report
I get an ICollection<int>
of ids. I use this collection to query the reference repository to get an ICollection<Reference>
like so:
from r in referencesRepository.References
where viewModel.ReferenceIds.Contains(r.Id)
select r
I would like to connect the collection straight to Report
like so:
report.References = from r in referencesRepository.References
where viewModel.ReferenceIds.Contains(r.Id)
select r;
This doesn't work because References
is an ICollection
and the result is an IEnumerable
. I can do ToList()
, but I think I will then load all of the references into memory. There also is no AddRange()
function.
I would like to be able to do this without loading them into memory.
My question is very similar to this 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 does come from the database. So I hope that it is somehow possible.
Thanks in advance.