1 // Copyright 2004-2008 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
22 /// Represents a query that can result in a value
23 /// of the type <typeparamref name="T"/>.
25 /// <typeparam name="T">The resulting object type</typeparam>
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.
30 public class ScalarQuery
<T
> : ScalarQuery
, IActiveRecordQuery
<T
>
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"/>.
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
)
47 /// Creates a new <c>ScalarQuery</c> for the giving <paramref name="query"/> and
48 /// the target ActiveRecord type specified in <paramref name="targetType"/>.
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
)
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"/>.
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
)
72 /// Creates a new <c>ScalarQuery</c> for the giving <paramref name="query"/> and
73 /// the target ActiveRecord type specified in <paramref name="targetType"/>.
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
)
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
;
93 /// Executes the query and gets the result.
97 object result
= ActiveRecordMediator
.ExecuteQuery(this);
98 return result
== null ? default(T
) : (T
) result
;