1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ActiveRecord
.Queries
18 using System
.Collections
;
23 /// Query that return a single result
25 public class ScalarQuery
: HqlBasedQuery
30 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
32 /// <param name="targetType">Type of the target.</param>
33 /// <param name="query">The query.</param>
34 /// <param name="positionalParameters">The positional parameters.</param>
35 public ScalarQuery(Type targetType
, string query
, params Object
[] positionalParameters
)
36 : base(targetType
, query
, positionalParameters
)
41 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
43 /// <param name="targetType">Type of the target.</param>
44 /// <param name="query">The query.</param>
45 public ScalarQuery(Type targetType
, string query
)
46 : base(targetType
, query
)
51 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
53 /// <param name="targetType">Type of the target.</param>
54 /// <param name="queryLanguage">The query language.</param>
55 /// <param name="query">The query.</param>
56 /// <param name="positionalParameters">The positional parameters.</param>
57 public ScalarQuery(Type targetType
, QueryLanguage queryLanguage
, string query
, params Object
[] positionalParameters
)
58 : base(targetType
, queryLanguage
, query
, positionalParameters
)
63 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
65 /// <param name="targetType">Type of the target.</param>
66 /// <param name="queryLanguage">The query language.</param>
67 /// <param name="query">The query.</param>
68 public ScalarQuery(Type targetType
, QueryLanguage queryLanguage
, string query
)
69 : base(targetType
, queryLanguage
, query
)
76 /// Executes the query and returns its scalar result.
78 /// <param name="session">The NHibernate's <see cref="ISession"/></param>
79 /// <returns>The query's scalar result</returns>
80 protected override object InternalExecute(ISession session
)
82 return CreateQuery(session
).UniqueResult();
86 /// Creates a single-position object array containing
87 /// the query's scalar result.
89 /// <param name="session">The NHibernate's <see cref="ISession"/></param>
90 /// <returns>An <c>object[1]</c> containing the query's scalar result.</returns>
91 protected override IEnumerable
InternalEnumerate(ISession session
)
93 return new Object
[] { InternalExecute(session) }
;