Rob Conery's blog has a way to do using a helper class he has, LazyList<T>
. Also he uses custom objects to avoid the join anonymous type issue.
I've used this successfully to get parent child relationships from sql without DataLoadOptions.
I think he covers it in either Pt2 or Pt3 of his MVC Storefront videos:
http://www.asp.net/learn/mvc-videos/video-351.aspx
http://www.asp.net/learn/mvc-videos/video-352.aspx
This assumes you have POCO called Category (not linq entity) and a LazyList class:
var categories = (from c in _db.Categories
select new Category
{
CategoryID = c.CategoryID,
CategoryName = c.CategoryName,
ParentCategoryID = c.ParentCategoryID,
SubCategories = new LazyList<Category>(
from sc in _db.Categories
where sc.ParentCategoryID == c.CategoryID
select new Category
{
CategoryID = sc.CategoryID,
CategoryName = sc.CategoryName,
ParentCategoryID = sc.ParentCategoryID
})
});