Entity Framework TPH는 판별 자 열을 감지합니다.

Akos Nagy

Discrimnator 열에 대한 인덱스를 자동으로 추가하는 사용자 지정 Entity Framework 마이그레이션 스캐 폴더 및 SQL 생성기를 구현하려고합니다. 이 솔루션을 구현하기 위해 어떤 열이 판별 자인지 감지하고 싶지만 지금까지 공식적이거나 비공식적 인 방법을 찾지 못했습니다.

SqlServerMigrationSqlGeneratorCSharpMigrationCodeGenerator 클래스 의 Generate () 메서드에 인수로 전달되는 ColumnModel 개체 의 내용을 검사하는 것으로 시작 했지만이를 가리키는 항목을 찾을 수 없습니다.

생성기 내부에서 판별자를 감지하는 수단이 있습니까? 아니면 컨텍스트에 포함 된 메타 데이터에서 가져온 것일까 요?

Akos Nagy

Github의 소스 코드를 살펴보고 정상적인 사람이해야하는 것보다 EF에 더 깊이 들어가면 작동하는 솔루션을 찾았다 고 생각합니다. 다른 사람이 필요할 경우를 대비하여 여기에 게시하십시오.

 var metadata = ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace;
 var entityTypes = metadata.GetItems<EntityType>(DataSpace.SSpace);
 // These are the entity sets
 var entitySets = metadata.GetItems<EntityContainer>(DataSpace.CSpace).Single().EntitySets;
 foreach (var entitySet in entitySets)
 {
   // The mapping for the entity set
   var mapping = metadata.GetItems<EntityContainerMapping>(DataSpace.CSSpace).Single().EntitySetMappings.Single(s => s.EntitySet == entitySet);
   // If there is more than one mapping for the entity set...
   if (mapping.EntityTypeMappings.Count > 0)
   {
     // This shows that these mappings belong to a hierarchy
     var hierarchyMapping = mapping.EntityTypeMappings.SingleOrDefault(etm => etm.IsHierarchyMapping);
     if (hierarchyMapping == null)
       continue;
     // Get the conditions that contain the discriminator columns and values
     var conditions = mapping.EntityTypeMappings.SelectMany(etm => etm.Fragments.Single().Conditions).OfType<ValueConditionMapping>().ToList();
     if (conditions.Select(cc => cc.Column).Distinct().Count() > 1)
     {
       Debug.WriteLine($"{mapping.EntitySet.Name} has multiple mappings one of them being a hierachy mapping, but the fragments' conditions refer more than one distinct edm property");
       continue;
     }
     if (conditions.Select(cc => cc.Column).Distinct().Count() < 1)
     {
       Debug.WriteLine($"{mapping.EntitySet.Name} has a hierachy mapping, but none of the fragments' conditions are ValueConditionMappings");
       continue;
     }
     // This is the discriminator's name in the database
     var discriminatorColumn = conditions.First().Column.Name;
   }
 }

기본 판별 자 열과 사용자 지정 판별 자 열을 사용하여이 솔루션을 테스트했으며 두 경우 모두 정상적으로 작동했습니다. 또한 TPT 및 TPC와 엔티티 분할 및 테이블 분할로 테스트했으며 모든 경우에 차별자가 표시되지 않았으므로 제대로 작동하는 것 같습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Entity Framework 6.1 판별 자 TPH

Entity Framework가 내보기 모델에 대한 판별 자 열을 만드는 이유는 무엇입니까?

Entity Framework에서 고유 인덱스의 일부로 판별 자 열 추가

Entity Framework는 런타임에 연결 문자열을 설정합니다.

Entity Framework Core는 문자열별로 테이블의 관련 데이터를 포함합니다.

Entity Framework-다중 열 인덱스를 식별자로 사용하는 Seed AddOrUpdate

Entity Framework (Linq 쿼리 사용)가 하위 쿼리를 다시 실행하는 대신 사용자 지정 필드의 별칭을 사용하도록합니다.

Entity Framework 5.0 식별자는 오류로 선언되어야합니다.

Entity Framework 5.0 식별자는 오류로 선언되어야합니다.

Entity Framework로 문자열을 자르는 방법은 무엇입니까?

Entity Framework 클래스에 별도의 매개 변수 대신 문자열 배열을 전달하는 방법이 있습니까?

Entity Framework는 문자열 SQL로 데이터를 필터링합니다.

업데이트 된 연결 문자열을 사용하지 않는 Entity Framework

Entity Framework는 열 집합을 고유하게 만듭니다.

Entity Framework는 OnModelCreating 중에 열이 있는지 확인합니다.

List.Contains ()는 문자열을 감지하지 못합니다.

Entity Framework Core는 ID 열을 존중하지 않습니다.

Typescript는 판별 자의 공용체 문자열 유형을 사용하여 ADT (차별 된 공용체 유형)의 인스턴스를 작성합니다.

Entity Framework는 자식 속성에서 SUM을 가져옵니다.

Entity Framework : Fluent API를 사용하여 열 유형을 고유 식별자로 설정하는 방법

Entity Framework Core는 탐색을 자동으로 수정하지 않습니다.

Entity Framework Core는 몇 가지 선택을 반환합니다.

잘못된 문자열 인코딩을 사용하는 Entity Framework?

Entity Framework 연결 문자열을 업데이트하는 방법

Entity Framework에서 숫자 문자열 열의 최대 값을 얻는 방법

수정 된 자식을 저장하지 않는 Entity Framework

Entity Framework Core Cosmos Db-대소 문자를 구분하지 않고 문자열을 비교하는 방법?

기본 유형이 IdentittyUser 인 경우 판별 자 열을 매핑하는 방법은 무엇입니까?

Entity Framework는 여러 열을 C # 복합 형식에 매핑합니다.

TOP 리스트

  1. 1

    Ionic 2 로더가 적시에 표시되지 않음

  2. 2

    JSoup javax.net.ssl.SSLHandshakeException : <url>과 일치하는 주체 대체 DNS 이름이 없습니다.

  3. 3

    std :: regex의 일관성없는 동작

  4. 4

    Xcode10 유효성 검사 : 이미지에 투명성이 없지만 여전히 수락되지 않습니까?

  5. 5

    java.lang.UnsatisfiedLinkError : 지정된 모듈을 찾을 수 없습니다

  6. 6

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  7. 7

    상황에 맞는 메뉴 색상

  8. 8

    SMTPException : 전송 연결에서 데이터를 읽을 수 없음 : net_io_connectionclosed

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    Windows cmd를 통해 Anaconda 환경에서 Python 스크립트 실행

  11. 11

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  12. 12

    C #에서 'System.DBNull'형식의 개체를 'System.String'형식으로 캐스팅 할 수 없습니다.

  13. 13

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  14. 14

    Cassandra에서 버전이 지정된 계층의 효율적인 모델링

  15. 15

    복사 / 붙여 넣기 비활성화

  16. 16

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  17. 17

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  18. 18

    SQL Server-현명한 데이터 문제 받기

  19. 19

    Seaborn에서 축 제목 숨기기

  20. 20

    ArrayBufferLike의 typescript 정의의 깊은 의미

  21. 21

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

뜨겁다태그

보관