Should I remove all inheritance from my model in order to work with ria services?

I've posted some questions on this before, but it's different.

So consider a small portion of our model:

  • Person
    • Customer
    • Employee
    • Spouse

Person is the base class which has 3 classes that inherit from it.

These 4 are very central in our design and link to many other entities. I could solve all the problems I'm experiencing with ria-services by removing the inheritance but that would really increase the complexety of the model.

The first problem I experienced was that I couldn't query for Customers, Employees or Spouses, but someone gave me a solution, which was to add something like this to the DomainService:

    public IQueryable<Employee> GetEmployees()
    {
        return this.ObjectContext.People.OfType<Employee>();
    }

    public IQueryable<Customer> GetCustomers()
    {
        return this.ObjectContext.People.OfType<Customer>();
    }

    public IQueryable<Spouse> GetSpouses()
    {
        return this.ObjectContext.People.OfType<Spouse>();            
    }

Next I tried something that seemed very normal to me:

var employee = new Employee()
{
    //.... left out to reduce the length of this question 
};

var spouse = new Spouse() 
{
    //.... left out to reduce the length of this questions
};

employee.Spouse = spouse;

context.People.Add(spouse);
context.People.Add(employee);
context.SubmitChanges();

Then I get the following exception:

Cannot retrieve an entity set for the derived entity type 'Spouse'. Use EntityContainer.GetEntitySet(Type) to get the entity set for the base entity type 'Person'.

Even when the spouse is already in the database, and I retreive it first I get similar exceptions.

Also note that for some reason in some places "Persons" is used instead of "People"...

So how do I solve this problem, what am I doing wrong and will I keep running into walls when using ria services with inheritance?

I found some references on the web, all saying it works and then some DomainService code in which they suposedly changed something but no details...

I'm using VS2010 RC1 + Silveright 4

Note: The data sources window that magically works in all the MIX sessions does not work for me... it never displays anything

Answers


This behavior was due to a bug in the RC1. It is discussed in more detail at http://forums.silverlight.net/forums/p/169599/384514.aspx#384514.

There is no known workaround for RC1, but the hierarchy you show should work fine in RC2. The bug centered around associations using derived types (EntityRef and EntityCollection), so I suspect the Spouse association was what triggered the bug in your scenario.

Regarding "Persons" v. "People" -- the name selection for the entity set comes from EF's pluralization for the entity names. The name of the query on the client comes from the corresponding query name in the DomainService, meaning you could expose a public IQueryable GetPeople() if you wanted.


Need Your Help

MyFaces vs Sun Reference Implementation of JSF

jsf myfaces

Maybe, some performance comparison or some noticeable specific differences is what I want to know.

Create jquery dropdown like RDP Menu Bar

jquery menu hidden rdp

I'm not all that familiar with jquery so I'm not quite sure how to do this. Basically, I want a block of html to stay hidden at the top of the page with a ~3px edge sticking out (something to mous...