Populating collections that subclass List<>

Sep 17, 2009 at 10:05 PM

I'm trying to populating a collection that subclasses of List<> and am running into a few hiccups. I'll reference the Northwind db throughout this example.

I'm trying to have a picture perfect object model and want to populate an "OrderCollection" rather than a List<Order>. I've only just started, but ran into an exception in BuildEntityExpression where Expression.Bind complains that "Argument types do not match". I was hoping someone could point me in the right direction. Thanks!


---- Modified IQToolkit - Northwind Code:

public class OrderCollection : List<OrderDetail>

public class Customer
    public string CustomerID;
    public string ContactName;
    public string CompanyName;
    public string Phone;
    public string City;
    public string Country;
    public OrderCollection Orders;

public class Order
    public int OrderID;
    public string CustomerID;
    public DateTime OrderDate;
    public Customer Customer;
    public List<OrderDetail> Details;

Sep 19, 2009 at 11:05 PM
Edited Sep 19, 2009 at 11:09 PM

You've defined OrderCollection as List<OrderDetail>.  I assume this is a mistake.  You'll also need to define a constructor that takes IEnumerable<Order> to get the query translator to work with your custom collection type.

public class OrderCollection : List<Order>
   public OrderCollection(IEnumerable<Order> orders)
      : base(orders)

Sep 21, 2009 at 10:37 PM

Yes sorry for that mistake, I meant for OrderCollection to inherit List<Order>. Thanks for the advice though, worked like a charm!