Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / EntityModel / SchemaObjectModel / KeyProperty.cs
1 //---------------------------------------------------------------------
2 // <copyright file="keyproperty.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       [....]
7 // @backupOwner [....]
8 //---------------------------------------------------------------------
9
10 using System;
11 using System.Collections;
12 using System.Collections.Generic;
13 using System.Diagnostics;
14 using System.Data.Metadata.Edm;
15
16
17 namespace System.Data.EntityModel.SchemaObjectModel
18 {
19     /// <summary>
20     /// Represents PropertyRef Element for Entity keys and referential constraints
21     /// </summary>
22     internal sealed class PropertyRefElement : SchemaElement
23     {
24         #region Instance Fields
25         private StructuredProperty _property = null;
26         #endregion
27
28         #region Public Methods
29         /// <summary>
30         /// construct a KeyProperty object
31         /// </summary>
32         /// <param name="parentElement"></param>
33         public PropertyRefElement(SchemaElement parentElement)
34             : base(parentElement)
35         {
36         }
37         #endregion
38
39         #region Public Properties
40         /// <summary>
41         /// property chain from KeyedType to Leaf property
42         /// </summary>
43         public StructuredProperty Property
44         {
45             get
46             {
47                 return _property;
48             }
49         }
50         #endregion
51
52         #region Private Methods
53
54         internal override void ResolveTopLevelNames()
55         {
56             Debug.Assert(false, "This method should never be used. Use other overload instead");
57         }
58
59         /// <summary>
60         /// Since this method can be used in different context, this method does not add any errors
61         /// Please make sure that the caller of this methods handles the error case and add errors 
62         /// appropriately
63         /// </summary>
64         /// <param name="entityType"></param>
65         /// <returns></returns>
66         internal bool ResolveNames(SchemaEntityType entityType)
67         {
68             if (string.IsNullOrEmpty(this.Name))
69             {
70                 // Don't flag this error. This must already must have flaged as error, while handling name attribute
71                 return true;
72             }
73
74             // Make sure there is a property by this name
75             _property = entityType.FindProperty(this.Name);
76
77             return (_property != null);
78         }
79
80         #endregion
81     }
82 }