I need to insert a new blank, but non null anonymous type into a list of other anonymous types returned by a linq query. Is that possible? All I can get are nulls
var something =
( from a in x.As
where x != null
join b in x.Bs
on a.key equals b.key
select new
{
a.prop1,
a.prop2,
b.prop1,
b.prop2,
b.prop3
}).ToList();
// insert blank
//something.InsertRange(0, something.DefaultIfEmpty());
//something.InsertRange(0, something.Take(0));
//?
I don’t know of a way to do it in a single query since the default for an anonymous type is
null. What I would do is pre-create a “default” item and append it if necessary:Note that as long as the field names match (in name and type)
blankwill be of the same anonymous type as the one created by the Linq query.