1 //------------------------------------------------------------------------------
2 // <copyright file="EntityRecordInfo.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
9 namespace System.Data.Common {
11 using System.Collections.Generic;
13 using System.Data.Metadata.Edm;
14 using System.Diagnostics;
17 /// EntityRecordInfo class providing a simple way to access both the type information and the column information.
19 public class EntityRecordInfo : DataRecordInfo {
21 private readonly EntityKey _entityKey;
22 private readonly EntitySet _entitySet;
27 /// <param name="metadata"></param>
28 /// <param name="memberInfo"></param>
29 /// <param name="entityKey"></param>
30 public EntityRecordInfo(EntityType metadata, IEnumerable<EdmMember> memberInfo, EntityKey entityKey, EntitySet entitySet)
31 : base(TypeUsage.Create(metadata), memberInfo) {
32 EntityUtil.CheckArgumentNull<EntityKey>(entityKey, "entityKey");
33 EntityUtil.CheckArgumentNull(entitySet, "entitySet");
35 _entityKey = entityKey;
36 _entitySet = entitySet;
37 ValidateEntityType(entitySet);
43 /// <param name="metadata"></param>
44 /// <param name="entityKey"></param>
45 internal EntityRecordInfo(EntityType metadata, EntityKey entityKey, EntitySet entitySet)
46 : base(TypeUsage.Create(metadata)) {
47 EntityUtil.CheckArgumentNull<EntityKey>(entityKey, "entityKey");
49 _entityKey = entityKey;
50 _entitySet = entitySet;
54 ValidateEntityType(entitySet);
58 Debug.Assert(false, "should always be valid EntityType when internally constructed");
65 /// Reusing TypeUsage and FieldMetadata from another EntityRecordInfo which has all the same info
66 /// but with a different EntityKey instance.
68 internal EntityRecordInfo(DataRecordInfo info, EntityKey entityKey, EntitySet entitySet)
71 _entityKey = entityKey;
72 _entitySet = entitySet;
76 ValidateEntityType(entitySet);
80 Debug.Assert(false, "should always be valid EntityType when internally constructed");
89 public EntityKey EntityKey {
95 // using EntitySetBase versus EntitySet prevents the unnecessary cast of ElementType to EntityType
96 private void ValidateEntityType(EntitySetBase entitySet)
98 if (!object.ReferenceEquals(RecordType.EdmType, null) &&
99 !object.ReferenceEquals(_entityKey, EntityKey.EntityNotValidKey) &&
100 !object.ReferenceEquals(_entityKey, EntityKey.NoEntitySetKey) &&
101 !object.ReferenceEquals(RecordType.EdmType, entitySet.ElementType) &&
102 !entitySet.ElementType.IsBaseTypeOf(RecordType.EdmType))
104 throw EntityUtil.Argument(System.Data.Entity.Strings.EntityTypesDoNotAgree);