Simply create instances of the concrete type (there is no requirement to use an anonymous types in LINQ):
var suppliers = SupplierView.Select()
.GroupBy(x => x.Name.Substring(0, 1).ToUpper(),
(alphanumeric, suppliers) => new AlphanumericSuppliers // concrete
{
Alphanumeric = alphanumeric,
Suppliers = suppliers.OrderBy(x => x.Name).ToList() // *
})
.OrderBy(x => x.Alphanumeric);
*As mentioned in comments, either change Suppliers
to be IEnumerable<Supplier>
or remove the ToList
call from here
3
solved Linq – cast anonymous type to concrete type