CastleのActiveRecordの新しいバージョンに追加されたSqlNamedQuery属性に問題があります。私が受け取る実行後Castle ActiveRecord: 'System.Int32'は 'System.Boolean'に変換できません。
IQuery query = Session.GetNamedQuery(Queries.GetItemName);
query.SetParameter("id", 1212, NHibernateUtil.Int64);
query.SetResultTransformer(Transformers.AliasToBean<Mapping>());
:
...
[Property(Access = PropertyAccess.AutomaticProperty, NotNull = true)]
public virtual bool IsPrimaryName { get; set; }
...
NHibernateのクエリ:私は、その結果マッピングでプロパティを宣言している
[assembly: SqlNamedQuery(Queries.GetItemName, "EXEC [dbo].[GetItemName] :id")]
それとは別に
:私はこのようにそれを指定しています以下の例外:
Object of type 'System.Int32' cannot be converted to type 'System.Boolean'.
以下のweb.configエントリも追加しましたが、成功しませんでした(たぶんhqlクエリにのみ適用されます)。
<add key="query.substitutions" value="true 1, false 0, yes 'Y', no 'N'" />
私の質問は - この問題を解決するにはどうすればよいですか?ストアドプロシージャは0または1を返しますが、私も '1'、 'true'、 'TRUE'などで試しました。どうすればこの問題を回避できますか?または、私はSqlNamedQueriesを削除する必要がありますか?
UPDATE:スタックトレース
[ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.Boolean'.]
System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) +4070954
System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) +9631414
System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) +151
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +223
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +101
System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +25
NHibernate.Properties.BasicSetter.Set(Object target, Object value) +68
がUPDATE:Selectステートメント:
SELECT
itm.ItemId AS ItemId,
itm.Value AS Value,
itm.Id AS ParentId,
1 AS IsPrimaryName
FROM
[dbo].[Item] AS itm
...
私は私の上に言及したように含むSP側で、いくつかの異なるシナリオ、試してみました: '1' を、 'true'、 'TRUE' + BIT変数を宣言してselectステートメントから直接返しますが、すべて同様の例外で失敗します。
Thx!
どちらの方言とどのバージョンのNHibernateを使用していますか? – jishi