views:

1097

answers:

2

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 quries 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 .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 .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?

+1  A: 

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

Bryant
After doing that, I'm now able to build the 2 projects separately; however, if I build the full solution, I get the error still. Thoughts? (besides just build separately :-) )
JamesEggers
A: 

The issue I discovered was that I had to have my Ria Service inherit from LinqToEntitiesDomainService instead of just Domain Service since the types being passed were Entities from EF.

JamesEggers