방법: Entity Framework 공급자를 사용하여 피드 사용자 지정(WCF Data Services)

WCF Data Services 를 사용하면 엔터티의 속성이 AtomPub 프로토콜에 정의된 사용하지 않은 요소에 매핑될 수 있도록 데이터 서비스 응답의 Atom serialization을 사용자 지정할 수 있습니다. 이 항목에서는 Entity Framework 공급자를 사용하여 .edmx 파일에 정의된 데이터 모델의 엔터티 형식에 대한 매핑 특성을 정의하는 방법을 보여 줍니다. 자세한 내용은 피드 사용자 지정(WCF Data Services)을 참조하십시오.

이 항목에서는 데이터 모델이 포함되어 있고 도구에서 생성된 .edmx 파일을 수동으로 수정합니다. Entity Designer에서 데이터 모델 확장을 지원하지 않으므로 파일을 수동으로 수정해야 합니다. 엔터티 데이터 모델 도구에서 생성되는 .edmx 파일에 대한 자세한 내용은 .edmx File Overview (Entity Framework)를 참조하십시오. 이 항목의 예제에서는 Northwind 샘플 데이터 서비스 및 자동 생성된 클라이언트 데이터 서비스 클래스를 사용합니다. 이 서비스 및 클라이언트 데이터 클래스는 WCF Data Services 퀵 스타트를 완료하면 만들어집니다.

Northwind.edmx 파일을 수동으로 수정하여 피드 사용자 지정 특성을 추가하려면

  1. 솔루션 탐색기에서 Northwind.edmx 파일을 마우스 오른쪽 단추로 클릭하고 연결 프로그램을 클릭합니다.

  2. 연결 프로그램 - Northwind.edmx 대화 상자에서 XML 편집기를 선택하고 확인을 클릭합니다.

  3. ConceptualModels 요소를 찾아 기존 Customers 엔터티 형식을 피드 사용자 지정 매핑 특성이 포함된 다음 요소로 바꿉니다.

    <EntityType Name="Customer"
                m:FC_SourcePath="CustomerID"
                m:FC_TargetPath="SyndicationTitle"
                m:FC_ContentKind="text"
                m:FC_KeepInContent="true">
      <Key>
        <PropertyRef Name="CustomerID" />
      </Key>
      <Property Name="CustomerID" Type="String" Nullable="false" MaxLength="5" 
                Unicode="true" FixedLength="true" />
      <Property Name="ContactName" Type="String" MaxLength="30"
          Unicode="true" FixedLength="false"
          m:FC_TargetPath="SyndicationAuthorName"
          m:FC_ContentKind="text"
          m:FC_KeepInContent="true"
          />
      <Property Name="CompanyName" Type="String" Nullable="false"
                MaxLength="40" Unicode="true" FixedLength="false"
                m:FC_TargetPath="CompanyName"
                m:FC_NsPrefix="Northwind"
                m:FC_NsUri="http://schemas.examples.microsoft.com/dataservices"
                m:FC_KeepInContent="true"
          />
      <Property Name="ContactTitle" Type="String" MaxLength="30" Unicode="true" FixedLength="false" 
                m:FC_TargetPath="SyndicationLinkHref"
                m:FC_ContentKind="text"
                m:FC_KeepInContent="true"
                m:FC_Criteria="SyndicationLinkRel"
                m:FC_CriteriaValue="http://NorthwindTraders.com/MyPhotos" />
      <Property Name="Address" Type="String" MaxLength="60" Unicode="true" FixedLength="false" />
      <Property Name="City" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
      <Property Name="Region" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
      <Property Name="PostalCode" Type="String" MaxLength="10" Unicode="true" FixedLength="false" />
      <Property Name="Country" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
      <Property Name="Phone" Type="String" MaxLength="24" Unicode="true" FixedLength="false" />
      <Property Name="Fax" Type="String" MaxLength="24" Unicode="true" FixedLength="false" />
      <NavigationProperty Name="Orders" Relationship="NorthwindModel.FK_Orders_Customers" 
                          FromRole="Customers" ToRole="Orders" />
    </EntityType>
    
  4. 변경 내용을 저장하고 Northwind.edmx 파일을 닫습니다.

  5. (선택 사항) Northwind.edmx 파일을 마우스 오른쪽 단추로 클릭하고 사용자 지정 도구 실행을 클릭합니다.

    이렇게 하면 필요한 개체 계층 파일이 다시 생성됩니다.

  6. 프로젝트를 다시 컴파일합니다.

예제

위의 예제에서는 URI http://myservice/ Northwind.svc/Customers('ALFKI')에 대해 다음 결과를 반환합니다.

<entry xml:base="https://localhost:12345/Northwind.svc/" 
       xmlns:d="https://schemas.microsoft.com/ado/2007/08/dataservices" 
       xmlns:m="https://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
       xmlns="http://www.w3.org/2005/Atom">
  <id>https://localhost:12345/Northwind.svc/Customers('ALFKI')</id>
  <title type="text">ALFKI</title>
  <updated>2009-07-27T07:59:43Z</updated>
  <author>
    <name>Peter Franken</name>
  </author>
  <link rel="edit" title="Customers" href="Customers('ALFKI')" />
  <link rel="https://schemas.microsoft.com/ado/2007/08/dataservices/related/Orders" 
        type="application/atom+xml;type=feed" title="Orders" 
        href="Customers('ALFKI')/Orders" />
  <category term="NorthwindModel.Customers" 
            scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <m:properties>
      <d:ContactName>Peter Franken</d:ContactName>
      <d:CompanyName>Alfreds Futterkiste</d:CompanyName>
      <d:ContactTitle>Marketing Manager</d:ContactTitle>
      <d:Address>Obere Str. 57</d:Address>
      <d:City>Berlin</d:City>
      <d:Region m:null="true" />
      <d:PostalCode>12209</d:PostalCode>
      <d:Country>Germany</d:Country>
      <d:Phone>089-0877310</d:Phone>
      <d:Fax>089-0877554</d:Fax>
    </m:properties>
  </content>
  <Northwind:CompanyName 
    xmlns:Northwind="http://schemas.examples.microsoft.com/dataservices">Alfreds Futterkiste</Northwind:CompanyName>
</entry>

참고 항목

개념

Entity Framework 공급자(WCF Data Services)