Filtering with DataLoadOptions and Associations

Answered Filtering with DataLoadOptions and Associations

  • Friday, November 02, 2007 3:44 PM
     
     

     

    Hi,

    Learning on how to use DataLoadOptions and associations

     

    lets suppose I want to return a Customer Object- orders and Order_Details

    However I dont want to retrieve all the fields but just some of them to be projected (eg 2 for each table) but still return a customer object not an anonymous type.

     


     

    var options = new DataLoadOptions();
    options.LoadWith<Customer> (c => c.Orders);
    options.AssociateWith<Customer>(c=c.orders.where(p=>p.EmployeeID=5));
    options.LoadWith<Order> (o => o.OrderDetails);
    dataContext.LoadOptions = options;

             Missing projection to return only a couple of fields from each table and then return the object how

             do I modify the below line or Can I modify the association?
            Customer cust = dataContext.Customers.Single (c => c.CustomerID == "ALFKI");

     

     

          I would like to make use of the power or LoadWith but still return an object ,

     

        Thanks a lot.

All Replies

  • Saturday, November 03, 2007 12:10 AM
     
     Answered
    This is not supposed to be possible - the final release of LINQ to SQL will throw an exception if you try Smile.

    If you want to populate just a subset of columns, you must either project into a custom type (with object initializers) or into an anonymous type.

    Regards

    Joe
  • Saturday, November 03, 2007 5:52 AM
     
     

    thanks a lot Joe,

    It was driving crazy!!!