Friday, November 02, 2007 3:44 PM
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.
Saturday, November 03, 2007 12:10 AMThis is not supposed to be possible - the final release of LINQ to SQL will throw an exception if you try .
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.
Saturday, November 03, 2007 5:52 AM
thanks a lot Joe,
It was driving crazy!!!