I tried this code for adding b
to books
:
IEnumerable<Book> books =null;
foreach (Book b in context.Books.AsEnumerable())
if (someConditions)
books = books.Concat(new[] {b});
but gives me this error on last line of code:
System.ArgumentNullException: Value cannot be null. Parameter name: first
it seems that null
Collection
could not concatenated. I use EF,so how should I initialize my Collection
that have no thing in it and I could concatenate to it?
Concat
on nullIEnumerable<Book> books = Enumerable.Empty<Book>();
IEnumerable<Book>
by concatting a lot of length-1 arrays of typeBook[]
. Consider filtering your books with LinqWhere
as in @Damith's comment, or maybe rewrite to useyield return b;
from the loop (extract this loop to a new method, an iterator block).