Search code examples
inheritanceentity-framework-4.1ef-code-firstwcf-ria-servicessilverlight-5.0

EF Code Fist inheritance with RIA Services and Silverlight


I'm playing around with EF and RIA Services for an upcoming project. For that project, I need inheritance to be able to abstract away concrete implementations of types. Lets say we have an abstract class CustomerBase. Customers in the US require other data than customers in the UK, so we can implement Customer : CustomerBase for the UK and the US in different modules. Other modules don't have to depend on a specific implementation, because CustomerBase already covers most ground.

I built a scenario like this and my tables are created just perfectly and the RIA Service copies them to the Silverlight (v5) client. But in the Silverlight project, a statement like this ...

CustomerBase customer = new Customer() { /* ... */ };

... is invalid, because the RIA Service lets all it's entities derive from Entity (CustomerBase is shared on the main module so everyone can access it).

How would you solve this? I saw this thread, but the I can't find a sample that does what I need (I guess the link is broken). Is there a way to make the statement above compile or is there a workaround for this kind of problem? I can't imagine I'm the first one having this requirement.


Solution

  • After loads of reading and discussions in ##[email protected], I think the best way to solve this is to create an implementation of CustomerBase on the Silverlight-Client that wraps the Customer entity generated by the RIA Services. In there I override all properties and let them access the Entitiy's fields and implement INotifyPropertyChanged on the fly.