Solved

WCF RIA Silverlight 4 Domain Service Key Attribute

Posted on 2010-08-19
4
1,746 Views
Last Modified: 2013-11-12
I am getting the below error when trying to add a stored procedure to my project. It is asking for a key to be defined. I have never had to do this for a stored proc. How would I go about this?

I am using Linq To Sql with WCF RIA

Error      1      The entity 'SP_Role_AreasResult' in DomainService 'Operations_DS' does not have a key defined. Entities exposed by DomainService operations must have at least one public property marked with the KeyAttribute.      Operations_Client_Silverlight
0
Comment
Question by:jimseiwert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
tovvenki earned 500 total points
ID: 33482578
Hi,
you need to add the metadata containing the key in a separate class
check this http://forums.silverlight.net/forums/p/163636/369183.aspx

Thanks and regards,
Venki
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 33484375
Maybe I am missing something but below is my code and the meta data but i still get the same error. What am i missing?
*************Meta Data
 <MetadataTypeAttribute(GetType(sp_role_areasresult.sp_role_areasresultMetadata))> _
    Partial Public Class sp_role_areasresult
        Friend NotInheritable Class sp_role_areasresultMetadata
            Private Sub New()
            End Sub

            <Key()> Public Area As String
            Public AreaOrder As Integer
        End Class
    End Class

************** My stored proc called in the domain service

    Public Function Role_Areas_Select(ByVal roleid As Integer) As IList(Of SP_Role_AreasResult)
        Return Me.DataContext.SP_Role_Areas(roleid).ToList()
    End Function

Open in new window

0
 
LVL 7

Expert Comment

by:vbigham
ID: 33533427
Someone had this problem and found that they were referencing the wrong version of System.ComponentModel.DataAnnotations

See this forum:
http://forums.silverlight.net/forums/p/148346/370241.aspx

That being said.  I will usually specify the primary key in the database or in the edmx model, and not use DomainService metadata (or very little).  Are either of those an option (PK in db or Model)?
0
 
LVL 2

Author Closing Comment

by:jimseiwert
ID: 33576768
After playing with this solution (way too long) I finally got it to work using the key function
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question