Fixing Brail Templates for VS Net wizards.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Framework / Queries / ScalarQuery.cs
blob55ca13f8b8ce9ed9f005e95549a106191b53d99f
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Collections;
20 using NHibernate;
22 /// <summary>
23 /// Query that return a single result
24 /// </summary>
25 public class ScalarQuery : HqlBasedQuery
27 #region Constructors
29 /// <summary>
30 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
31 /// </summary>
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)
40 /// <summary>
41 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
42 /// </summary>
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)
50 /// <summary>
51 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
52 /// </summary>
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)
62 /// <summary>
63 /// Initializes a new instance of the <see cref="ScalarQuery"/> class.
64 /// </summary>
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)
73 #endregion
75 /// <summary>
76 /// Executes the query and returns its scalar result.
77 /// </summary>
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();
85 /// <summary>
86 /// Creates a single-position object array containing
87 /// the query's scalar result.
88 /// </summary>
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) };