I am getting a runtime exception and can't figure out why
Unable to cast object of type 'System.Collections.Generic.List`1[Foo.ElementNameViewModel]' to type 'Foo.ElementNameList'.
The classes I have are
ElementNameList - a list of a particular type
namespace Foo
{
public class ElementNameList : List<ElementNameViewModel> {}
}
ElementNameViewModel - an item to be in a list
namespace Foo
{
public class ElementNameViewModel
{
public string Symbol { get; set; }
public string Name { get; set; }
}
}
and the exception occurs in a controller at
var elements = (ElementNameList) db.Elements
.Select(c => new ElementNameViewModel
{
Symbol = c.Symbol,
Name = c.Name
})
.OrderBy(e => e.Symbol)
.ToList();
Not sure how I should refactor the elements list if subclassing List is not done.