Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Mapping / ViewGeneration / QueryRewriting / RoleBoolean.cs
1 //---------------------------------------------------------------------
2 // <copyright file="RoleBoolean.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 namespace System.Data.Mapping.ViewGeneration.Structures
11 {
12     using System.Collections.Generic;
13     using System.Data.Common.CommandTrees;
14     using System.Data.Entity;
15     using System.Data.Metadata.Edm;
16     using System.Diagnostics;
17     using System.Text;
18
19     /// <summary>
20     /// Denotes the fact that the key of the current tuple comes from a specific extent, or association role.
21     /// </summary>
22     internal sealed class RoleBoolean : TrueFalseLiteral
23     {
24         #region Constructor
25         internal RoleBoolean(EntitySetBase extent)
26         {
27             m_metadataItem = extent;
28         }
29         internal RoleBoolean(AssociationSetEnd end)
30         {
31             m_metadataItem = end;
32         }
33         #endregion
34
35         #region Fields
36         private readonly MetadataItem m_metadataItem;
37         #endregion
38
39         #region BoolLiteral members
40         /// <summary>
41         /// Not supported in this class.
42         /// </summary>
43         internal override StringBuilder AsEsql(StringBuilder builder, string blockAlias, bool skipIsNotNull)
44         {
45             Debug.Fail("Should not be called.");
46             return null; // To keep the compiler happy
47         }
48
49         /// <summary>
50         /// Not supported in this class.
51         /// </summary>
52         internal override DbExpression AsCqt(DbExpression row, bool skipIsNotNull)
53         {
54             Debug.Fail("Should not be called.");
55             return null; // To keep the compiler happy
56         }
57
58         internal override StringBuilder AsUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
59         {
60             AssociationSetEnd end = m_metadataItem as AssociationSetEnd;
61             if (end != null)
62             {
63                 builder.Append(Strings.ViewGen_AssociationSet_AsUserString(blockAlias, end.Name, end.ParentAssociationSet));
64             }
65             else
66             {
67                 builder.Append(Strings.ViewGen_EntitySet_AsUserString(blockAlias, m_metadataItem.ToString()));
68             }
69             return builder;
70         }
71
72         internal override StringBuilder AsNegatedUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
73         {
74             AssociationSetEnd end = m_metadataItem as AssociationSetEnd;
75             if (end != null)
76             {
77                 builder.Append(Strings.ViewGen_AssociationSet_AsUserString_Negated(blockAlias, end.Name, end.ParentAssociationSet));
78             }
79             else
80             {
81                 builder.Append(Strings.ViewGen_EntitySet_AsUserString_Negated(blockAlias, m_metadataItem.ToString()));
82             }
83             return builder;
84         }
85
86         internal override void GetRequiredSlots(MemberProjectionIndex projectedSlotMap, bool[] requiredSlots)
87         {
88             throw new NotImplementedException();
89         }
90
91         protected override bool IsEqualTo(BoolLiteral right)
92         {
93             RoleBoolean rightBoolean = right as RoleBoolean;
94             if (rightBoolean == null)
95             {
96                 return false;
97             }
98             return m_metadataItem == rightBoolean.m_metadataItem;
99         }
100
101         public override int GetHashCode()
102         {
103             return m_metadataItem.GetHashCode();
104         }
105
106         internal override BoolLiteral RemapBool(Dictionary<MemberPath, MemberPath> remap)
107         {
108             return this;
109         }
110         #endregion
111
112         #region Other Methods
113         internal override void ToCompactString(StringBuilder builder)
114         {
115             AssociationSetEnd end = m_metadataItem as AssociationSetEnd;
116             if (end != null)
117             {
118                 builder.Append("InEnd:" + end.ParentAssociationSet + "_" + end.Name);
119             }
120             else
121             {
122                 builder.Append("InSet:" + m_metadataItem.ToString());
123             }
124         }
125         #endregion
126     }
127 }