EntityPropertyMappingAttribute 클래스

정의

WCF Data Services에서 반환하는 피드의 엔터티 요소와 엔터티 형식의 속성 간에 사용자 지정 매핑을 지정하는 특성입니다.

public ref class EntityPropertyMappingAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
public sealed class EntityPropertyMappingAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)>]
type EntityPropertyMappingAttribute = class
    inherit Attribute
Public NotInheritable Class EntityPropertyMappingAttribute
Inherits Attribute
상속
EntityPropertyMappingAttribute
특성

예제

다음 예제에서는 형식의 Order 두 속성이 모두 기존 피드 요소에 매핑됩니다. Product 형식의 Item 속성은 별도의 네임스페이스의 사용자 지정 피드 특성에 매핑됩니다.

using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;

namespace CustomDataService
{
    [EntityPropertyMappingAttribute("Customer",
        SyndicationItemProperty.AuthorName,
        SyndicationTextContentKind.Plaintext, true)]
    [EntityPropertyMapping("OrderId",
        SyndicationItemProperty.Title,
        SyndicationTextContentKind.Plaintext, false)]
    [DataServiceKeyAttribute("OrderId")]
    public class Order
    {
        public int OrderId { get; set; }
        public string Customer { get; set; }
        public IList<Item> Items { get; set; }
    }
    [EntityPropertyMappingAttribute("Product", "productname",
     "orders", "http://schema.examples.microsoft.com/dataservices", true)]
    [DataServiceKeyAttribute("Product")]
    public class Item
    {
        public string Product { get; set; }
        public int Quantity { get; set; }
    }
    public partial class OrderItemData
    {
        #region Populate Service Data
        static IList<Order> _orders;
        static IList<Item> _items;
        static OrderItemData()
        {
            _orders = new Order[]{
              new Order(){ OrderId=0, Customer = "Peter Franken", Items = new List<Item>()},
              new Order(){ OrderId=1, Customer = "Ana Trujillo", Items = new List<Item>()}};
            _items = new Item[]{
              new Item(){ Product="Chai", Quantity=10 },
              new Item(){ Product="Chang", Quantity=25 },
              new Item(){ Product="Aniseed Syrup", Quantity = 5 },
              new Item(){ Product="Chef Anton's Cajun Seasoning", Quantity=30}};
            _orders[0].Items.Add(_items[0]);
            _orders[0].Items.Add(_items[1]);
            _orders[1].Items.Add(_items[2]);
            _orders[1].Items.Add(_items[3]);
        }
        #endregion
        public IQueryable<Order> Orders
        {
            get { return _orders.AsQueryable(); }
        }
        public IQueryable<Item> Items
        {
            get { return _items.AsQueryable(); }
        }
    }

    public class OrderItems : DataService<OrderItemData>
    {
        // This method is called only once to initialize
        //service-wide policies.
        public static void InitializeService(DataServiceConfiguration
                                             config)
        {
            config.SetEntitySetAccessRule("Orders",
               EntitySetRights.AllRead |
               EntitySetRights.AllWrite);
            config.SetEntitySetAccessRule("Items",
                EntitySetRights.AllRead |
                EntitySetRights.AllWrite);
            config.DataServiceBehavior.MaxProtocolVersion =
                DataServiceProtocolVersion.V2;
        }
    }
}
Imports System.Collections.Generic
Imports System.Data.Services
Imports System.Data.Services.Common
Imports System.Linq

Namespace CustomDataService
    <EntityPropertyMappingAttribute("Customer", _
        SyndicationItemProperty.AuthorName, _
        SyndicationTextContentKind.Plaintext, True)> _
    <EntityPropertyMapping("OrderId", _
        SyndicationItemProperty.Title, _
        SyndicationTextContentKind.Plaintext, False)> _
    <DataServiceKeyAttribute("OrderId")> _
    Public Class Order
        Private _orderId As Integer
        Private _customer As String
        Private _items As IList(Of Item)
        Public Property OrderId() As Integer
            Get
                Return _orderId
            End Get
            Set(ByVal value As Integer)
                _orderId = value
            End Set
        End Property
        Public Property Customer() As String
            Get
                Return _customer
            End Get
            Set(ByVal value As String)
                _customer = value
            End Set
        End Property
        Public Property Items() As IList(Of Item)
            Get
                Return _items
            End Get
            Set(ByVal value As IList(Of Item))
                _items = value
            End Set
        End Property
    End Class
    <EntityPropertyMappingAttribute("Product", "productname", _
        "orders", "http://schema.examples.microsoft.com/dataservices", True)> _
    <DataServiceKeyAttribute("Product")> _
    Public Class Item
        Private _product As String
        Private _quantity As Integer
        Public Property Product() As String
            Get
                Return _product
            End Get
            Set(ByVal value As String)
                _product = value
            End Set
        End Property
        Public Property Quantity() As Integer
            Get
                Return _quantity
            End Get
            Set(ByVal value As Integer)
                _quantity = value
            End Set
        End Property
    End Class
    Partial Public Class OrderItemData
#Region "Populate Service Data"
        Shared _orders As IList(Of Order)
        Shared _items As IList(Of Item)
        Sub New()
            _orders = New Order() { _
                New Order() With {.OrderId = 0, .Customer = "Peter Franken", .Items = New List(Of Item)()}, _
              New Order() With {.OrderId = 1, .Customer = "Ana Trujillo", .Items = New List(Of Item)()}}
            _items = New Item() { _
              New Item() With {.Product = "Chai", .Quantity = 10}, _
              New Item() With {.Product = "Chang", .Quantity = 25}, _
              New Item() With {.Product = "Aniseed Syrup", .Quantity = 5}, _
              New Item() With {.Product = "Chef Anton's Cajun Seasoning", .Quantity = 30}}
            _orders(0).Items.Add(_items(0))
            _orders(0).Items.Add(_items(1))
            _orders(1).Items.Add(_items(2))
            _orders(1).Items.Add(_items(3))
        End Sub
#End Region
        Public ReadOnly Property Orders() As IQueryable(Of Order)
            Get
                Return _orders.AsQueryable()
            End Get
        End Property
        Public ReadOnly Property Items() As IQueryable(Of Item)
            Get
                Return _items.AsQueryable()
            End Get
        End Property
    End Class
    Public Class OrderItems
        Inherits DataService(Of OrderItemData)
        ' This method is called only once to initialize
        ' service-wide policies.
        Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
            config.SetEntitySetAccessRule("Orders", _
                                          EntitySetRights.AllRead _
                                          Or EntitySetRights.AllWrite)
            config.SetEntitySetAccessRule("Items", _
                                          EntitySetRights.AllRead _
                                          Or EntitySetRights.AllWrite)
            config.DataServiceBehavior.MaxProtocolVersion =
                DataServiceProtocolVersion.V2
        End Sub
    End Class
End Namespace

이전 예제에서는 URI http://myservice/OrderItems.svc/Orders(0)?$expand=Items에 대해 다음 결과를 반환합니다.

<entry xml:base="http://localhost:12345/OrderItems.svc/" 
       xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
       xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
       xmlns="http://www.w3.org/2005/Atom">
  <id>http://localhost:12345/OrderItems.svc/Orders(0)</id>
  <title type="text">0</title>
  <updated>2009-07-25T21:12:30Z</updated>
  <author>
    <name>Peter Franken</name>
  </author>
  <link rel="edit" title="Order" href="Orders(0)" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Items" 
        type="application/atom+xml;type=feed" title="Items" href="Orders(0)/Items">
    <m:inline>
      <feed>
        <title type="text">Items</title>
        <id>http://localhost:12345/OrderItems.svc/Orders(0)/Items</id>
        <updated>2009-07-25T21:12:30Z</updated>
        <link rel="self" title="Items" href="Orders(0)/Items" />
        <entry>
          <id>http://localhost:12345/OrderItems.svc/Items('Chai')</id>
          <title type="text" />
          <updated>2009-07-25T21:12:30Z</updated>
          <author>
            <name />
          </author>
          <link rel="edit" title="Item" href="Items('Chai')" />
          <category term="CustomDataService.Item" 
                    scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
          <content type="application/xml">
            <m:properties>
              <d:Product>Chai</d:Product>
              <d:Quantity m:type="Edm.Int32">10</d:Quantity>
            </m:properties>
          </content>
          <orders:productname 
            xmlns:orders="http://schema.examples.microsoft.com/dataservices">Chai</orders:productname>
        </entry>
        <entry>
          <id>http://localhost:12345/OrderItems.svc/Items('Chang')</id>
          <title type="text" />
          <updated>2009-07-25T21:12:30Z</updated>
          <author>
            <name />
          </author>
          <link rel="edit" title="Item" href="Items('Chang')" />
          <category term="CustomDataService.Item" 
                    scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
          <content type="application/xml">
            <m:properties>
              <d:Product>Chang</d:Product>
              <d:Quantity m:type="Edm.Int32">25</d:Quantity>
            </m:properties>
          </content>
          <orders:productname 
            xmlns:orders="http://schema.examples.microsoft.com/dataservices">Chang</orders:productname>
        </entry>
      </feed>
    </m:inline>
  </link>
  <category term="CustomDataService.Order" 
            scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <m:properties>
      <d:Customer>Peter Franken</d:Customer>
    </m:properties>
  </content>
</entry>

설명

EntityPropertyMappingAttribute 플렉션 공급자의 데이터 모델에서 사용자 지정 피드 매핑을 정의하는 데 사용됩니다. 이 특성은 클래스를 생성하는 데 사용되는 메타데이터가 사용자 지정 피드 매핑이 데이터 모델에 정의되어 있음을 나타내는 경우 생성된 클라이언트 데이터 서비스 클래스에도 적용됩니다. 이 정보는 클라이언트가 사용자 지정 피드를 지원하는 메시지를 만들고 사용할 수 있도록 하는 데 필요합니다. 자세한 내용은 피드 사용자 지정을 참조하세요.

생성자

EntityPropertyMappingAttribute(String, String, String, String, Boolean)

속성을 사용자 지정 피드 요소에 매핑하는 EntityPropertyMappingAttribute 클래스의 인스턴스를 만듭니다.

EntityPropertyMappingAttribute(String, SyndicationItemProperty, SyndicationTextContentKind, Boolean)

EntityPropertyMappingAttribute의 새 인스턴스를 만듭니다.

속성

KeepInContent

피드의 콘텐츠 섹션과 매핑된 위치에 속성 값이 모두 반복되어야 하는지 여부를 나타내는 부울 값을 가져옵니다.

SourcePath

피드의 지정된 요소에 매핑될 신디케이션 항목의 속성 이름을 가져옵니다.

TargetNamespacePrefix

TargetNamespaceUri와 함께 TargetPath 요소가 존재하는 네임스페이스를 지정하는 문자열 값을 가져옵니다.

TargetNamespaceUri

TargetPath 속성으로 지정된 요소의 네임스페이스 URI를 지정하는 문자열 값을 가져옵니다.

TargetPath

속성이 매핑되는 피드의 사용자 지정 대상 이름을 가져옵니다.

TargetSyndicationItem

SyndicationItem 클래스에서 속성을 가져옵니다.

TargetTextContentKind

EntityPropertyMappingAttribute에 의해 매핑된 속성의 콘텐츠 형식을 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보