locked
RIA service with hierarchy of types RRS feed

  • Question

  • I have a base class called Party which models the various parties that a company deals with, in my domain model Party is abstract.  There are several concrete classes which derive from Party - Person, Company, InterestGroup, etc.  Further the concrete class Employee derives from Person.

    Other classes in the domain model have properties whose type is Party, never one of the concrete types. (eg a Project has a property called Customer of type Party)

    In the domain model I have added a KnownTypeAttribute to Party for each of the derived classes.

    I am using Entity Framework for my ORM and a unit of work pattern to access repositories.

    The domain service I created looks like

    public class MyDomainService : DomainService
    {
       [Import]
       public IUnitOfWork unitOfWork {get; set;}
    
    //Constructor uses MEF to initialize unitOfWork 
    
       [Query(IsDefault = true)]
       public IQueryable<Party> GetParties()
       {
          return unitOfWork.Parties.AllParties();
       }
    
       [Query(IsDeault = true)]
       public IQueryable<Company> GetCompanies()
       {
          return unitOfWork.Parties.AllCompanies();
       }
    
       [Query(IsDefault = true)]
       public IQueryable<Person> GetPeople()
       {
          return unitOfWork.Parties.AllPeople();
       }
    
       // Etc for other concrete classes
    }

    When I try to add the RIA service as a Data Source in LightSwitch 2012 I get

    Both query operations 'GetCompanies' and 'GetParties' cannot be marked as the default query operation.  Entity type 'Company' derives from 'Party'. The default query can expose only a single type for an entity hierarchy.

    If I comment out the 'GetParties()' service then LS will let me import the concrete classes (haven't tried Employee yet, I'll get to that later).  But other types like Project have any property which refers to Party excluded (Project is missing the Customer property, for example).

    If I comment out all the 'GetCompanies', 'GetPeople', etc but leave 'GetParties' then the concrete types (Person, Company, etc) are not created in Lightswitch because they do not have a default query defined.

    How do I make LS2012 (or 2013) work with a fairly ordinary polymorphic setup?  Of course, I will eventually want to be able to CRUD the polymorphic types and those types which refer to a polymorphic type.  My full model has other instances of polymorphism but I assume that if I can get one to work then the others will be the same.

    Do I need to ditch LightSwitch and go to a more hand-crafted Silverlight or WPF (+ MVC for web client) approach?


    Paul Linton

    Wednesday, August 14, 2013 12:25 AM