Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Common / QueryCache / EntitySqlQueryCacheKey.cs
blobc768adabf19aa9f515383acca898f143499c1826
1 //------------------------------------------------------------------------------
2 // <copyright file="EntitySqlQueryCacheKey.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //------------------------------------------------------------------------------
10 namespace System.Data.Common.QueryCache
12 using System;
13 using System.Data.Objects;
14 using System.Diagnostics;
16 /// <summary>
17 /// Represents an Entity-SQL-based ObjectQuery Cache key context
18 /// </summary>
19 internal sealed class EntitySqlQueryCacheKey : QueryCacheKey
21 /// <summary>
22 /// Aggregate hashcode based the hashcode of the properties of this cache key
23 /// </summary>
24 private readonly int _hashCode;
26 /// <summary>
27 /// The name of the default container in effect when the Entity-SQL text was parsed
28 /// (affects whether or not the text can be successfully parsed)
29 /// </summary>
30 private string _defaultContainer;
32 /// <summary>
33 /// Entity Sql statement
34 /// </summary>
35 private readonly string _eSqlStatement;
37 /// <summary>
38 /// Parameter collection token
39 /// </summary>
40 private readonly string _parametersToken;
42 /// <summary>
43 /// Number of parameters
44 /// </summary>
45 private readonly int _parameterCount;
47 /// <summary>
48 /// Concatenated representation of the Include span paths
49 /// </summary>
50 private readonly string _includePathsToken;
52 /// <summary>
53 /// The merge option in effect
54 /// </summary>
55 private readonly MergeOption _mergeOption;
57 /// <summary>
58 /// Result type affects assembly plan.
59 /// </summary>
60 private readonly Type _resultType;
62 /// <summary>
63 /// Creates a new instance of ObjectQueryCacheKey given a entityCommand instance
64 /// </summary>
65 /// <param name="defaultContainerName">The default container name in effect when parsing the query (may be null)</param>
66 /// <param name="eSqlStatement">The Entity-SQL text of the query</param>
67 /// <param name="parameterCount">The number of parameters to the query</param>
68 /// <param name="parametersToken">A string representation of the parameters to the query (may be null)</param>
69 /// <param name="includePathsToken">A string representation of the Include span paths in effect (may be null)</param>
70 /// <param name="mergeOption">The merge option in effect. Required for result assembly.</param>
71 internal EntitySqlQueryCacheKey(string defaultContainerName,
72 string eSqlStatement,
73 int parameterCount,
74 string parametersToken,
75 string includePathsToken,
76 MergeOption mergeOption,
77 Type resultType)
78 : base()
80 Debug.Assert(null != eSqlStatement, "eSqlStatement must not be null");
82 _defaultContainer = defaultContainerName;
83 _eSqlStatement = eSqlStatement;
84 _parameterCount = parameterCount;
85 _parametersToken = parametersToken;
86 _includePathsToken = includePathsToken;
87 _mergeOption = mergeOption;
88 _resultType = resultType;
90 int combinedHash = _eSqlStatement.GetHashCode() ^
91 _mergeOption.GetHashCode();
93 if (_parametersToken != null)
95 combinedHash ^= _parametersToken.GetHashCode();
98 if (_includePathsToken != null)
100 combinedHash ^= _includePathsToken.GetHashCode();
103 if (_defaultContainer != null)
105 combinedHash ^= _defaultContainer.GetHashCode();
108 _hashCode = combinedHash;
111 /// <summary>
112 /// Determines equality of two cache keys based on cache context values
113 /// </summary>
114 /// <param name="otherObject"></param>
115 /// <returns></returns>
116 public override bool Equals(object otherObject)
118 Debug.Assert(null != otherObject, "otherObject must not be null");
119 if (typeof(EntitySqlQueryCacheKey) != otherObject.GetType())
121 return false;
124 EntitySqlQueryCacheKey otherObjectQueryCacheKey = (EntitySqlQueryCacheKey)otherObject;
126 // also use result type...
127 return (_parameterCount == otherObjectQueryCacheKey._parameterCount) &&
128 (_mergeOption == otherObjectQueryCacheKey._mergeOption) &&
129 Equals(otherObjectQueryCacheKey._defaultContainer, _defaultContainer) &&
130 Equals(otherObjectQueryCacheKey._eSqlStatement, _eSqlStatement) &&
131 Equals(otherObjectQueryCacheKey._includePathsToken, _includePathsToken) &&
132 Equals(otherObjectQueryCacheKey._parametersToken, _parametersToken) &&
133 Equals(otherObjectQueryCacheKey._resultType, _resultType);
136 /// <summary>
137 /// Returns the hashcode for this cache key
138 /// </summary>
139 /// <returns></returns>
140 public override int GetHashCode()
142 return _hashCode;
145 /// <summary>
146 /// Returns a string representation of the state of this cache key
147 /// </summary>
148 /// <returns>
149 /// A string representation that includes query text, parameter information, include path information
150 /// and merge option information about this cache key.
151 /// </returns>
152 public override string ToString()
154 return String.Join("|", new string[] { _defaultContainer, _eSqlStatement, _parametersToken, _includePathsToken, Enum.GetName(typeof(MergeOption), _mergeOption) });