I want to create a DDD repository that returns IQueryable Entities that match the Linq to SQL underlying classes, minus any relations. I can easily return Entities minus th
Try something like this:
public class AnnouncementCategory : //...
{
public int ID { get; set; }
public string Name { get; set; }
}
.. and in your repo:
public IQueryable GetAnnouncementCategories()
{
return from ac in this._dc.AnnouncementCategories
let announcements = this.GetAnnouncementsByCategory(ac.ID)
select new AnnouncementCategory
{
ID = ac.ID,
Name = ac.Text,
Announcements = new LazyList(announcements)
};
}
private IQueryable GetAnnouncementsByCategory(int categoryID)
{
return GetAnnouncements().Where(a => a.Category.ID == categoryID);
}
This way, instead of projecting into an anonymous type, i'm projecting into a new instance of my AnnouncementCategory class. You can ignore the GetAnnouncementsByCategory function if you like, this is used to chain the collection of associated Announcement objects for each category but in a way so that they can be lazy loaded with IQueryable (ie. so that when i do eventually call on this property, i don't have to call the entire collection. i can do more LINQ on this to filter).