views:

328

answers:

1

How i can use Inheritance in Entity Framework with .NET RIA Services? Problem: if there is inheritance in EF, silverlight application don't compiled. Can you help me?

+1  A: 

This:

Type 'Common.Individual' is a direct or indirect subclass of Type 'Common.Customer'. DomainServices cannot return a Type that is a subclass of another Type returned from the same DomainService.

...does not mean "no inheritance support." It does mean that (in the current version of RIA services) you can't return both a parent and a child type to the client.

That is a limitation, and it's a limitation you have to live with in RIA Services for now. That said, I don't think it's as big as a limitation as the thread you reference implies. Is not the same as saying you cannot use inheritance at all. Also, I think that inheritance tends to be overused in entity mapping for reasons I explain in great detail in this presentation.

So while I can't fix the limitation, my suggestions are:

  • Use composition instead of inheritance when appropriate (cf. the presentation referenced above).
  • When you must use inheritance, RIA Services will require that you don't return the parent type.
Craig Stuntz