Linq to sql LoadWith returned limit fields

Is it possible to use LoadWith but specify return fields?

For example, if I have two tables 1) Products 2) Categories

and do something like

DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<Products>(d => d.Categories);
db.LoadOptions = dlo;

MyDataContext db = new MyDataContext();
var result = from d in db.Products
             select d;

when I check the query in the profiler, I see that ALL rows from the category table are returned. All I really need is a "Name" field.

I know that I can rewrite the query using joins, but I need to return the result set as the "Data" data type, so I use LoadWith.

+5
source share
2 answers

No, this is not possible with LoadWith.

, : 1 ( 1 ).

+1

, anynomus

select new {Order = order, ProductName = order.Product.Name,
             CustomerName = order.Customer.Name,
             OrderType = order.OrderType.Name } // etc
0

All Articles