DataServiceKeyAttribute Class
This page is specific to:.NET Framework Version:3.5Silverlight 34.0
.NET Framework Class Library
DataServiceKeyAttribute Class

Denotes the key property or properties of an entity.

Namespace:  System.Data.Services.Common
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)
Syntax

'Usage

Dim instance As DataServiceKeyAttribute

'Declaration

<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := False)> _
Public NotInheritable Class DataServiceKeyAttribute _
    Inherits Attribute
Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.Data.Services.Common..::.DataServiceKeyAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5 SP1
See Also

Reference

Community Content

Wrong description or bug?
Added by:DanVladut
DataServiceKeyAttribute is obviously an attribute that can only be used on a class, but looking at its description and further more from the example provided here:

http://msdn.microsoft.com/en-us/library/cc668799.aspx

one will normally think t it should be a Property attribute, used to mark the key property of a class from the business layer (the example in the article doesn't work, of course).

Luckyly forums cleared out this problem for me, the way to use DataServiceKeyAttribute lays in its constructor where one can pass the name(s) of the property(properties) used as key.


PS. Initially I was asking here how to use DataServiceKeyAttribute.

What it does
Added by:Michael Ibarrra, MCPD
The DataServiceKeyAttribute lets the Entity Framework know which property members of a class uniquely identify an instance of that class. In other words, the property or properties that make up the "primary key," if you will.

For example: Windows Azure Table Services require that Entities to be stored in by the service declare three properties: PartitionKey, RowKey, and Timestamp. Of these properties, the unique combination of PartitionKey and Row key makes up the EntityKey for instances of that class.

Usage would look something like


[DataServiceKey("PartitionKey", "RowKey")]
public class MyClass {...


Anyway, hope that helps!

Mike
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View