So I already have everything mapped out in my edmx file
I created the following
public sealed class ACategory:example.org.Data.Categories
{
public ACategory()
{
}
public int PostingCount
{
get;
set;
}
}
I then decided to figure out how to do a compiled query, just cause it seems cool as hell to do.
public static Func<MyEntities, IQueryable<ACategory>> GetCategoriesWithPostingCount =
CompiledQuery.Compile((MyEntities entities) => from category in entities.Categories.Include("Postings_Categories")
select new ACategory
{
CategoryID =category.CategoryID,
ParentCategoryID = category.ParentCategoryID,
CategoryName = category.CategoryName,
CategoryDescription = category.CategoryDescription,
PostingCount = category.Postings_Categories.Count
});
It freakin works… way cool I can now call this easily from anywhere.
My question now is this? Is this a good way to do this or am I making a mistake on something that could be lurking behind the scenes?
If you do this, you have to expose your data context. This is not a problem if you are using the compiled query in your DAL alone, but is something to think about. It is a concise way to create business objects, though!