score:0

Accepted answer

Thanks to the comments on this question, i was able to accomplish this using the query below.

public IEnumerable<Category> GetChildlessCategories()
{
    return WowContext.Categories
    .GroupJoin(
        WowContext.Categories.Where(category => category.ParentCategoryId.HasValue),
        (category) => category.CategoryId,
        (child) => child.ParentCategoryId.Value,
        (category, children) => new { Children = children, Category = category })
    .Where(a => !a.Children.Any())
    .Select(a => a.Category).ToList();
}

Related Articles