InheritanceMappingAttribute 클래스

정의

LINQ to SQL 애플리케이션의 상속 계층 구조를 매핑합니다.

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

예제

이 예제에서는 상위 매핑된 클래스(Shape)가 추상인 계층 구조에 대한 상속 매핑을 보여 줍니다.

public enum ShapeType
{
    Square = 0, Circle = 1
}
[Table(Name = "Shape")]
[InheritanceMapping(Code = ShapeType.Square, Type = typeof(Square),
    IsDefault = true)]
[InheritanceMapping(Code = ShapeType.Circle, Type = typeof(Circle))]

abstract public class Shape
{
    [Column(IsDiscriminator = true)]
    public ShapeType ShapeType = 0;
}

public class Square : Shape
{
    [Column]
    public int Side = 0;
}
public class Circle : Shape
{
    [Column]
    public int Radius = 0;
}
Public Enum ShapeType As Integer
    Square = 0
    Circle = 1
End Enum

<Table(Name:="Shape")> _
<InheritanceMapping(Code:=ShapeType.Square, Type:=GetType(Square), _
    IsDefault:=True)> _
<InheritanceMapping(Code:=ShapeType.Circle, Type:=GetType(Circle))> _
Public MustInherit Class Shape
    <Column(IsDiscriminator:=True)> _
        Public ShapeType As ShapeType = 0
End Class

Public Class Square
    Inherits Shape
    <Column()> _
    Public Side As Integer = 0
End Class

Public Class Circle
    Inherits Shape
    <Column()> _
    Public Radius As Integer = 0
End Class

다음 예제에서는 매핑되지 않은 클래스를 포함하는 방법을 보여 줍니다. 계층 구조의 어디에서나 매핑되지 않은 클래스를 배치할 수 있습니다.

// Unmapped and not queryable.
class A {  }

// Mapped and queryable.
[Table]
[InheritanceMapping(Code = "B", Type = typeof(B),
IsDefault = true)]
[InheritanceMapping(Code = "D", Type = typeof(D))]
class B: A {  }

// Unmapped and not queryable.
class C: B {  }

// Mapped and queryable.
class D: C {  }

// Unmapped and not queryable.
class E: D {  }
' Unmapped and not queryable.
Class A
End Class

' Mapped and queryable.
<Table()> _
<InheritanceMapping(Code:="B", Type:=GetType(B), _
IsDefault:=True)> _
<InheritanceMapping(Code:="D", Type:=GetType(D))> _
Class B
    Inherits A
End Class

' Unmapped and not queryable.
Class C
    Inherits B
End Class

' Mapped and queryable.
Class D
    Inherits C
End Class

' Unmapped and not queryable.
Class E
    Inherits D
End Class

설명

InheritanceMappingAttribute 하나는 매핑된 클래스별로 지정됩니다.

상속 계층 구조를 매핑할 때 다음 사항에 유의하세요.

  • 계층 구조의 모든 클래스는 단일 테이블에 매핑되어야 합니다.

  • 계층 구조의 맨 위에 있는 매핑된 형식에서 상속 계층 구조에 대한 테이블을 선언해야 합니다. 최상위 클래스에서 파생된 클래스의 테이블 또는 매핑 특성을 지정할 수 없습니다.

  • 계층 구조에서 인터페이스를 사용할 수 있지만 LINQ는 인터페이스를 매핑하지 않습니다.

  • 클래스를 매핑할 때 계층에서 클래스를 건너뛸 수 있지만 매핑된 클래스에 대해서만 쿼리할 수 있습니다.

올바른 구체화를 위해 판별자 코드 값은 고유해야 하며 데이터베이스의 값과 일치해야 합니다. 대/소문자를 구분하여 정확하게 일치하지 않는 판별자 코드 값이 있는 행은 set을 사용하여 IsDefault 클래스를 인스턴스화합니다 true.

생성자

Name Description
InheritanceMappingAttribute()

InheritanceMappingAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

Name Description
Code

매핑된 상속 계층의 판별자 코드 값을 가져오거나 설정합니다.

IsDefault

판별자 값이 지정된 값과 일치하지 않을 때 이 형식의 개체가 인스턴스화되었는지 여부를 가져오거나 설정합니다.

Type

계층 구조에서 클래스의 형식을 가져오거나 설정합니다.

TypeId

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

(다음에서 상속됨 Attribute)

메서드

Name Description
Equals(Object)

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

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

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

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

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

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

파생 클래스에서 재정의되는 경우 이 인스턴스의 값이 파생 클래스의 기본값인지 여부를 나타냅니다.

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

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

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

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

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

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

Name Description
_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)

적용 대상