Tuesday, November 2, 2010

Complex types in RIA Services: base types or entities?

When we designed complex types for WCF RIA Services V1 SP1, we had a hot debate. Are complex types like base types or entities? Well, they are a bit of both.

They are like base types in the sense:
  1. They are structured values; not objects with identity
  2. They can be used for entity members or DomainService method parameters
  3. There is no inheritance or association (inbound or outbound) support
They are like entities in the sense
  1. They are code-gen'ed
  2. They are deeply change tracked, validated (with error reporting) when used in an entity
They are definitely not intended to be substituted for entities. They are not meant to replace composition where the composed object is an entity.

Samples of intended use:
Customer.Address where address does not have an identity of its own
Shape.Coordinate where coordinate is used like a value (no associations etc)

Samples of unintended use:
In place of composition -
Order.OrderDetail // OrderDetail if captured in a separate relational entity likely has its own ID and associations
For many-to-many link entity/table
Course.Registration or Student.Registration // another entity with its ID

In this round, we didn't really get a chance to provide a mechanism to use a complex types like a base-type - with essentially a portable assembly across Silverlight and .NET. That was a scoping decision based on priority feedback from a few MVPs we regularly talk to.

For more about the feature use and all the bells and whistles see Mathew's detailed blog post.

What is your scenario for complex types? Do the beta bits releases at PDC work well for your scenarios?

Thanks.
Dinesh