locked
Entity Framework and Opt Out Models RRS feed

  • Question

  • Activity Category Schema

    I have an issue that I have yet to find a way to solve using the entity framework.  Before diving into the issue I’ll give a quick overview of the application.  The application is a Silverlight application, early market research says that having 10000+ accounts in the first year is not unreasonable.  I am using wcf services for the DAL, a client side set of model/viewmodel/view classes. 

    During account setup and within account maintenance a series of activity lists/categories/labels are managed.  We have approximately 100 activity categories at this time that are considered “System Defined”.  Clients can choose to Opt Out of system defined categories, and can create their own.  Within the schema an activitycategory that has a null value in “AccountId” is considered to be “SystemDefined”.  The client can only opt out of a system defined category, but can create and edit categories.  The challenge is to present all of this in easy to understand manner.  As such I have defined two new data members on the partial ActivityCategory class in the DAL:

    1. SystemDefined(bool) returns true if AccountId is null.
    2. Included(bool) return true if there is not an ActivityCategoryOptOut record that matchs the ActivityCategoryId and the AccountId.

     

    The trouble is #2, I can find no way to populate that field within the DAL without using a DTO (which makes excessive roundtripping to the database).  I hope that someone can advise me on how to accomplish this.  Currently I am including the OptOuts and using client side code to set the Included flag.  As this site becomes larger this will become potentially excessive in regards to the “on the wire” size.

     

    =========Current code in the DAL to return activity categories.

    public IQueryable<ActivityCategory> ActivityCategories(int accountid)

            {

                varset =

                    ObjectContext.ActivityCategories.Include("OptOuts").Include("ActivityLabels").Include("Activities").

                        Include("Glyph").Include("Activities.OptOuts").Include("ActivityLabels.OptOuts")

                        .Where(a => a.AccountId == accountid || a.AccountId == 0 || a.AccountId == null).OrderBy(

                            cat => cat.Name);

               

                returnset;

            }

    Wednesday, March 28, 2012 2:51 PM

All replies