Extended 속성(CSDL)
EDM(엔터티 데이터 모델)에서 확장 속성은 xmlns="https://schemas.microsoft.com/ado/2006/04/edm"
으로 식별되는 시스템 네임스페이스가 아니라 사용자의 네임스페이스에서 정의되고 존재하는 속성입니다. CSDL(개념 스키마 정의 언어)이 두 종류의 속성을 정의하는 데 모두 사용됩니다. 확장 속성을 CSDL 스키마에 추가하려면 네임스페이스를 정의한 다음 이를 엔터티 형식 및 해당 엔터티 집합의 정의에 사용합니다.
다음 예제에서는 네임스페이스 xmlns:o1="http://other.contoso.com/schema"
를 정의합니다. 네임스페이스 접두사인 o1
은 엔터티 형식 AWBuildVersion 및 엔터티 집합 AWBuildVersions의 정의에서 별칭 역할을 합니다.
<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="AdventureWorksModel" Alias="Self"
xmlns="https://schemas.microsoft.com/ado/2006/04/edm"
xmlns:o1="http://other.contoso.com/schema">
<EntityContainer Name="AdventureWorksEntities"
o1:MyCustomAttribute="MyCustomAttributeValue">
<EntitySet Name="AWBuildVersions"
EntityType="Adventureworks.AWBuildVersion"
o1:AnotherAttribute="AnotherAttributeValue"/>
</EntityContainer>
…...
<EntityType Name="AWBuildVersion">
<Key>
<PropertyRef Name="SystemInformationID" />
</Key>
<Property Name="SystemInformationID"
Type="Byte" Nullable="false" />
<Property Name="Database_Version" Type="String"
Nullable="false" />
<Property Name="VersionDate"
Type="DateTime" Nullable="false" />
<Property Name="ModifiedDate"
Type="DateTime" Nullable="false" />
</EntityType>
PropertyKind는 MetadataProperty 개체에 있는 열거형으로서 EDM에서 시스템 속성과 확장 속성을 식별하는 데 사용할 수 있습니다. 코드에서 이 열거형을 사용하는 예제는 AdventureWorks 개체 모델 사용(EDM)을 참조하십시오.
확장 속성을 사용하는 코드 실행
확장 속성이 있는 스키마 수정은 AdventureWorks 전체 모델(EDM)의 데이터 모델과 응용 프로그램 코드를 사용하여 테스트할 수 있습니다. AdventureWorks 항목에 설명된 대로 CDSL 스키마에 수정을 추가하고 Edmgen.exe를 통해 개체 모델을 다시 빌드할 수 있습니다.
그런 다음 다음 코드를 AdventureWorks 개체 모델 사용(EDM) 항목의 클라이언트 응용 프로그램에 추가합니다. 이 메서드는 Program
클래스에 추가해야 하며 DisplayProperties
함수를 참조하는 주석의 코드에서 호출해야 합니다.
public static void DisplayProperties(
MetadataWorkspace workspace, DataSpace model)
{
// Get a collection of the entity containers.
ReadOnlyCollection<EntityContainer> containers =
workspace.GetItems<EntityContainer>(model);
// Iterate through collection to get each entity container.
foreach (EntityContainer container in containers)
{
// Display extended properties for the entity container.
DisplayExtendedProperties(container);
// Iterate through collection to get each entity set.
foreach (EntitySetBase baseSet in container.BaseEntitySets)
{
// Check if this instance is an EntitySet.
if (baseSet is EntitySet)
{
// Display extended properties for the entity set.
DisplayExtendedProperties(baseSet);
}
}
}
// Get a collection of the entity types.
ReadOnlyCollection<EntityType> entities =
workspace.GetItems<EntityType>(model);
// Iterate through the collection to get each entity type.
foreach (EntityType entity in entities)
{
// Display the extended properties for the entity type.
DisplayExtendedProperties(entity);
}
}
private static void DisplayExtendedProperties(MetadataItem item)
{
foreach (MetadataProperty property in item.MetadataProperties)
{
if (property.PropertyKind == PropertyKind.Extended)
Console.WriteLine(string.Format("\t{0}\t{1}\t{2}",
item.GetType().Name, property.Name, property.Value));
}
}
참고 항목
개념
AdventureWorks 전체 개념 스키마(EDM)
AdventureWorks 전체 저장소 스키마(EDM)
AdventureWorks 전체 매핑 스키마(EDM)
AdventureWorks 개체 모델 사용(EDM)