1 //------------------------------------------------------------------------------
2 // <copyright file="EntitySqlQueryCacheKey.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //------------------------------------------------------------------------------
10 namespace System
.Data
.Common
.QueryCache
13 using System
.Data
.Objects
;
14 using System
.Diagnostics
;
17 /// Represents an Entity-SQL-based ObjectQuery Cache key context
19 internal sealed class EntitySqlQueryCacheKey
: QueryCacheKey
22 /// Aggregate hashcode based the hashcode of the properties of this cache key
24 private readonly int _hashCode
;
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)
30 private string _defaultContainer
;
33 /// Entity Sql statement
35 private readonly string _eSqlStatement
;
38 /// Parameter collection token
40 private readonly string _parametersToken
;
43 /// Number of parameters
45 private readonly int _parameterCount
;
48 /// Concatenated representation of the Include span paths
50 private readonly string _includePathsToken
;
53 /// The merge option in effect
55 private readonly MergeOption _mergeOption
;
58 /// Result type affects assembly plan.
60 private readonly Type _resultType
;
63 /// Creates a new instance of ObjectQueryCacheKey given a entityCommand instance
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
,
74 string parametersToken
,
75 string includePathsToken
,
76 MergeOption mergeOption
,
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
;
112 /// Determines equality of two cache keys based on cache context values
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())
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
);
137 /// Returns the hashcode for this cache key
139 /// <returns></returns>
140 public override int GetHashCode()
146 /// Returns a string representation of the state of this cache key
149 /// A string representation that includes query text, parameter information, include path information
150 /// and merge option information about this cache key.
152 public override string ToString()
154 return String
.Join("|", new string[] { _defaultContainer, _eSqlStatement, _parametersToken, _includePathsToken, Enum.GetName(typeof(MergeOption), _mergeOption) }
);