Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Mapping / StorageConditionPropertyMapping.cs
1 //---------------------------------------------------------------------
2 // <copyright file="StorageConditionPropertyMapping.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.Generic;
12 using System.Text;
13 using System.Diagnostics;
14 using System.Data.Metadata.Edm;
15
16 namespace System.Data.Mapping {
17     /// <summary>
18     /// Mapping metadata for Conditional property mapping on a type.
19     /// Condition Property Mapping specifies a Condition either on the C side property or S side property.
20     /// </summary>
21     /// <example>
22     /// For Example if conceptually you could represent the CS MSL file as following
23     /// --Mapping 
24     ///   --EntityContainerMapping ( CNorthwind-->SNorthwind )
25     ///     --EntitySetMapping
26     ///       --EntityTypeMapping
27     ///         --MappingFragment
28     ///           --EntityKey
29     ///             --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
30     ///           --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
31     ///           --ConditionProperyMap ( constant value-->SMemberMetadata )
32     ///       --EntityTypeMapping
33     ///         --MappingFragment
34     ///           --EntityKey
35     ///             --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
36     ///           --ComplexPropertyMap
37     ///             --ComplexTypeMap
38     ///               --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
39     ///               --ScalarProperyMap ( CMemberMetadata-->SMemberMetadata )
40     ///           --ConditionProperyMap ( constant value-->SMemberMetadata )
41     ///     --AssociationSetMapping 
42     ///       --AssociationTypeMapping
43     ///         --MappingFragment
44     ///           --EndPropertyMap
45     ///             --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
46     ///             --ScalarProperyMap ( CMemberMetadata-->SMemberMetadata )
47     ///           --EndPropertyMap
48     ///             --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
49     /// This class represents the metadata for all the condition property map elements in the 
50     /// above example.
51     /// </example>
52     internal class StorageConditionPropertyMapping : StoragePropertyMapping {
53         #region Constructors
54         /// <summary>
55         /// Construct a new condition Property mapping object
56         /// </summary>
57         /// <param name="cdmMember"></param>
58         /// <param name="columnMember"></param>
59         /// <param name="value"></param>
60         /// <param name="isNull"></param>
61         internal StorageConditionPropertyMapping(EdmProperty cdmMember, EdmProperty columnMember
62             , object value, Nullable<bool> isNull) : base(cdmMember) {
63             Debug.Assert((cdmMember != null) || (columnMember != null), "Both CDM and Column Members can not be specified for Condition Mapping");
64             Debug.Assert((cdmMember == null) || (columnMember == null), "Either CDM or Column Members has to be specified for Condition Mapping");
65             Debug.Assert((isNull.HasValue) || (value != null), "Both Value and IsNull can not be specified on Condition Mapping");
66             Debug.Assert(!(isNull.HasValue) || (value == null), "Either Value or IsNull has to be specified on Condition Mapping");
67             this.m_columnMember = columnMember;
68             this.m_value = value;
69             this.m_isNull = isNull;
70         }
71         #endregion
72
73         #region Fields
74         /// <summary>
75         /// Column EdmMember for which the condition is specified.
76         /// </summary>
77         EdmProperty m_columnMember;
78         /// <summary>
79         /// Value for the condition thats being mapped.
80         /// </summary>
81         object m_value;
82         bool? m_isNull;
83         #endregion
84
85         #region Properties
86         /// <summary>
87         /// Value for the condition
88         /// </summary>
89         internal object Value {
90             get {
91                 return this.m_value;
92             }
93         }
94
95         /// <summary>
96         /// Whether the property is being mapped to Null or NotNull
97         /// </summary>
98         internal Nullable<bool> IsNull {
99             get {
100                 return this.m_isNull;
101             }
102         }
103
104
105         /// <summary>
106         /// ColumnMember for which the Condition Map is being specified
107         /// </summary>
108         internal EdmProperty ColumnProperty {
109             get {
110                 return this.m_columnMember;
111             }
112         }
113         #endregion
114
115         #region Methods
116         /// <summary>
117         /// This method is primarily for debugging purposes.
118         /// Will be removed shortly.
119         /// </summary>
120         /// <param name="index"></param>
121         internal override void Print(int index) {
122             StorageEntityContainerMapping.GetPrettyPrintString(ref index);
123             StringBuilder sb = new StringBuilder();
124             sb.Append("ConditionPropertyMapping");
125             sb.Append("   ");
126             if (this.EdmProperty != null) {
127                 sb.Append("Name:");
128                 sb.Append(this.EdmProperty.Name);
129                 sb.Append("   ");
130             }
131             if (this.ColumnProperty != null) {
132                 sb.Append("Column Name:");
133                 sb.Append(this.ColumnProperty.Name);
134                 sb.Append("   ");
135             }
136             if (this.Value != null) {
137                 sb.Append("Value:");
138                 sb.Append("'" + Value + "'");
139                 sb.Append("   ");
140                 sb.Append("Value CLR Type:");
141                 sb.Append("'" + Value.GetType() + "'");
142                 sb.Append("   ");
143             }
144             sb.Append("Value TypeMetadata:");
145             EdmType memberType = (ColumnProperty != null) ? ColumnProperty.TypeUsage.EdmType : null;
146             if (memberType != null)
147             {
148                 sb.Append("'" + memberType.FullName + "'");
149                 sb.Append("   ");
150             }
151             if (this.IsNull.HasValue) {
152                 sb.Append("IsNull:");
153                 sb.Append(this.IsNull);
154                 sb.Append("   ");
155             }
156             Console.WriteLine(sb.ToString());
157         }
158         #endregion
159     }
160 }