Fixing an issue with output parameters that are of type IntPtr
[castle.git] / ActiveRecord / Castle.ActiveRecord / Framework / Queries / ScalarQuery.Generic.cs
blob257ef826cf191f5a2748be3c4123c63c193336c5
1 // Copyright 2004-2008 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;
19 using NHibernate;
21 /// <summary>
22 /// Represents a query that can result in a value
23 /// of the type <typeparamref name="T"/>.
24 /// </summary>
25 /// <typeparam name="T">The resulting object type</typeparam>
26 /// <remarks>
27 /// If the query result is null, and <typeparamref name="T"/> is a value type,
28 /// the default value for that type will be returned.
29 /// </remarks>
30 public class ScalarQuery<T> : ScalarQuery, IActiveRecordQuery<T>
32 #region Constructors
33 /// <summary>
34 /// Creates a new <c>ScalarQuery</c> for the giving <paramref name="query"/>,
35 /// using the specified positional <paramref name="positionalParameters"/> and
36 /// the target ActiveRecord type specified in <paramref name="targetType"/>.
37 /// </summary>
38 /// <param name="targetType">The target ActiveRecord type</param>
39 /// <param name="query">The query</param>
40 /// <param name="positionalParameters">The positional positionalParameters</param>
41 public ScalarQuery(Type targetType, String query, params Object[] positionalParameters)
42 : base(targetType, query, positionalParameters)
46 /// <summary>
47 /// Creates a new <c>ScalarQuery</c> for the giving <paramref name="query"/> and
48 /// the target ActiveRecord type specified in <paramref name="targetType"/>.
49 /// </summary>
50 /// <param name="targetType">The target ActiveRecord type</param>
51 /// <param name="query">The query</param>
52 public ScalarQuery(Type targetType, String query)
53 : base(targetType, query)
57 /// <summary>
58 /// Creates a new <c>ScalarQuery</c> for the giving <paramref name="query"/>,
59 /// using the specified positional <paramref name="positionalParameters"/> and
60 /// the target ActiveRecord type specified in <paramref name="targetType"/>.
61 /// </summary>
62 /// <param name="targetType">The target ActiveRecord type</param>
63 /// <param name="queryLanguage">The language of the query</param>
64 /// <param name="query">The query</param>
65 /// <param name="positionalParameters">The positional positionalParameters</param>
66 public ScalarQuery(Type targetType, QueryLanguage queryLanguage, String query, params Object[] positionalParameters)
67 : base(targetType, queryLanguage, query, positionalParameters)
71 /// <summary>
72 /// Creates a new <c>ScalarQuery</c> for the giving <paramref name="query"/> and
73 /// the target ActiveRecord type specified in <paramref name="targetType"/>.
74 /// </summary>
75 /// <param name="targetType">The target ActiveRecord type</param>
76 /// <param name="queryLanguage">The language of the query</param>
77 /// <param name="query">The query</param>
78 public ScalarQuery(Type targetType, QueryLanguage queryLanguage, String query)
79 : base(targetType, queryLanguage, query)
82 #endregion
84 #region IActiveRecordQuery<T> implementation
85 T IActiveRecordQuery<T>.Execute(ISession session)
87 object result = InternalExecute(session);
88 return result == null ? default(T) : (T)result;
90 #endregion
92 /// <summary>
93 /// Executes the query and gets the result.
94 /// </summary>
95 public T Execute()
97 object result = ActiveRecordMediator.ExecuteQuery(this);
98 return result == null ? default(T) : (T) result;