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

Posted by TimothyP on Stack Overflow See other posts from Stack Overflow or by TimothyP
Published on 2010-03-28T12:59:14Z Indexed on 2010/03/28 13:03 UTC
Read the original article Hit count: 299

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

© Stack Overflow or respective owner

Related posts about dotnet

Related posts about Silverlight