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

3 comments:

  1. My plan is this:

    I have a standard DomainService for my regular Entity stuff. But I also created an DomainService for some non-database driven service calls. This should allow me to abstract out my service calls and keep things nice and neat.

    My serivce calls will return complex objects that I can use directly in my client.

    Well, that's the hope anyway. I am still not able to get it working just yet. I just got the SP1 installed, but I am having trouble using complex objects from other assemblies.

    Thanks for the post...

    -Scott

    ReplyDelete
  2. Hi,
    my complex type is like below:
    Custom
    {
    string name,
    string desc,
    Entity entity
    }

    and I want to return it to the client, but I wasn't able to
    Thanks,
    Aran

    ReplyDelete