1 //---------------------------------------------------------------------
2 // <copyright file="StorageConditionPropertyMapping.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
13 using System.Diagnostics;
14 using System.Data.Metadata.Edm;
16 namespace System.Data.Mapping {
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.
22 /// For Example if conceptually you could represent the CS MSL file as following
24 /// --EntityContainerMapping ( CNorthwind-->SNorthwind )
25 /// --EntitySetMapping
26 /// --EntityTypeMapping
29 /// --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
30 /// --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
31 /// --ConditionProperyMap ( constant value-->SMemberMetadata )
32 /// --EntityTypeMapping
35 /// --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
36 /// --ComplexPropertyMap
38 /// --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
39 /// --ScalarProperyMap ( CMemberMetadata-->SMemberMetadata )
40 /// --ConditionProperyMap ( constant value-->SMemberMetadata )
41 /// --AssociationSetMapping
42 /// --AssociationTypeMapping
45 /// --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
46 /// --ScalarProperyMap ( CMemberMetadata-->SMemberMetadata )
48 /// --ScalarPropertyMap ( CMemberMetadata-->SMemberMetadata )
49 /// This class represents the metadata for all the condition property map elements in the
52 internal class StorageConditionPropertyMapping : StoragePropertyMapping {
55 /// Construct a new condition Property mapping object
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;
69 this.m_isNull = isNull;
75 /// Column EdmMember for which the condition is specified.
77 EdmProperty m_columnMember;
79 /// Value for the condition thats being mapped.
87 /// Value for the condition
89 internal object Value {
96 /// Whether the property is being mapped to Null or NotNull
98 internal Nullable<bool> IsNull {
100 return this.m_isNull;
106 /// ColumnMember for which the Condition Map is being specified
108 internal EdmProperty ColumnProperty {
110 return this.m_columnMember;
117 /// This method is primarily for debugging purposes.
118 /// Will be removed shortly.
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");
126 if (this.EdmProperty != null) {
128 sb.Append(this.EdmProperty.Name);
131 if (this.ColumnProperty != null) {
132 sb.Append("Column Name:");
133 sb.Append(this.ColumnProperty.Name);
136 if (this.Value != null) {
138 sb.Append("'" + Value + "'");
140 sb.Append("Value CLR Type:");
141 sb.Append("'" + Value.GetType() + "'");
144 sb.Append("Value TypeMetadata:");
145 EdmType memberType = (ColumnProperty != null) ? ColumnProperty.TypeUsage.EdmType : null;
146 if (memberType != null)
148 sb.Append("'" + memberType.FullName + "'");
151 if (this.IsNull.HasValue) {
152 sb.Append("IsNull:");
153 sb.Append(this.IsNull);
156 Console.WriteLine(sb.ToString());