JamesEggers
JamesEggers

Reputation: 12935

Silverlight to RIA Service to Business Objects Causes Build Errors

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?

Upvotes: 2

Views: 2635

Answers (2)

JamesEggers
JamesEggers

Reputation: 12935

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.

Upvotes: 0

Bryant
Bryant

Reputation: 8670

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

Upvotes: 2

Related Questions