R – Silverlight to RIA Service to Business Objects Causes Build Errors

entity-frameworksilverlightwcf-ria-services

I've went through the basic tutorials associated with Silverlight and Ria Services and I am now trying to branch out to a model I have used before.

I have a Silverlight project that I want to use Ria Services with. Unlike the tutorials for Ria Services that I've seen, I'm wanting to have my Domain Services to use Repository objects in a Business Object (DLL) project that holds my domain entities (created using EF).

Here's an example snippet of a domain service I'm working with:

[EnableClientAccess()]
public class ContactService : DomainService
{
    public List<Contact> ContactSearch(string lastName)
    {
        ContactRepository rep = new ContactRepository();
        return rep.SearchByLastName(lastName);
    }
}

Contact and ContactRepository are in my Business Objects project. ContactRepository queries EF for the Contact Entities.

When I build, I get the following error:

The entity
'SilverlightCRM.BusinessObjects.Contact'
does not have a key defined. Entities
exposed by DomainService operations
must have must have at least one
property marked with the KeyAttribute.

If I change the entity generated code to decorate the Contact.ContactID property with the System.ComponentModel.DataAnnotation.Key() attribute as described here, I get another build error in my <projectname>.g.cs file of my project containing my domain service.

Type of Namespace 'Data' does not
exist in namespace 'System' (are you
missing an assembly reference?)

Since the <projectname>.g.cs file is autogenerated on build, just commenting out a line doesn't work and I have System.Data as a project reference.

What am I doing wrong here? I would think that I'd be able to use this model of organizing aspects of my solution but do I have to change things if I want to use Ria Services?

Best Answer

Make sure you're referencing the System.ComponentModel.DataAnnotations dll from the RIA services folder (it has a version of 99.0.0.0).

Related Topic