views:

616

answers:

1

So i have been playing around with the .NET RIA Services with Silverlight, and i created a new DomainService based on a couple entities from a LINQ2SQL DataContext.

When i tried to compile, i got this error:

Error 2 The entity 'Data.Service' does not have a key defined. Entities exposed by DomainService operations must have must have at least one property marked with the KeyAttribute. Portal

So i added a metadata class for the Service object like so:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace Data
{
    [MetadataType(typeof(Service.ServiceMetadata))]
    public partial class Service
    {
        internal sealed class ServiceMetadata
        {
            [Key]
            public int PublicAPI;
        }
    }
}

Now i get this error:

Error 4 The associated metadata type for type 'Data.Service' contains the following unknown properties or fields: PublicAPI. Please make sure that the names of these members match the names of the properties on the main type. Portal

PublicAPI is definitely defined in the main object as generated by L2S, the namespaces are the same. Any ideas as to what i might be doing wrong?

I realize that the .NET RIA services is still CTP, but this seems like a fundamental part of the framework that should be working.

A: 

I solved this problem. The DataContext that was referring to was in another assembly, and the partial classes i was defining were in the Web Project so there was some kind of disconnect between the versions of the classes that the system was trying to use.

Moving the datacontext into the web project solved it.

Jason Miesionczek