Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6075117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:27:30+00:00 2026-05-23T10:27:30+00:00

I’m having some problems with the SqlNamedQuery attribute that has been added to the

  • 0

I’m having some problems with the SqlNamedQuery attribute that has been added to the newer version of Castle’s ActiveRecord. I have specified it like this:

[assembly: SqlNamedQuery(Queries.GetItemName, "EXEC [dbo].[GetItemName] :id")]

Apart from that I have a property in the result mapping declared as:

...
[Property(Access = PropertyAccess.AutomaticProperty, NotNull = true)]
public virtual bool IsPrimaryName { get; set; }
...

Nhibernate query:

IQuery query = Session.GetNamedQuery(Queries.GetItemName);
query.SetParameter("id", 1212, NHibernateUtil.Int64);
query.SetResultTransformer(Transformers.AliasToBean<Mapping>());

After execution I receive the following exception:

Object of type 'System.Int32' cannot be converted to type 'System.Boolean'.

I have also added the below web.config entry but with no success (probably it only applies to hql queries).

<add key="query.substitutions" value="true 1, false 0, yes 'Y', no 'N'" />

So, my question is – how can I resolve this problem? The stored procedure returns 0 or 1 but I’ve also tried with ‘1’, ‘true’, ‘TRUE’ etc. How can I get around this? Or maybe I should just drop the SqlNamedQueries?

UPDATE: Stack Trace

[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 statement:

SELECT  
        itm.ItemId AS ItemId,
        itm.Value AS Value,
        itm.Id AS ParentId,
        1 AS IsPrimaryName
FROM    
        [dbo].[Item] AS itm
...

As I’ve mentioned above I have tried several different scenarios on the sp side, including: ‘1’, ‘true’, ‘TRUE’ + declaring a BIT variable and returning it directly from the select statement but it all fails with similar exception.

Thx!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:27:31+00:00Added an answer on May 23, 2026 at 10:27 am

    Query substitutions are used to map HQL literals to SQL, so they won’t help here.

    Your stacktrace is incomplete (you ate the inner exception) so I can’t be sure, but I’d guess the error is that GetItemName returns an int column which you’re trying to map that to a bool property.

    Can you post the relevant SELECT from the SP, and your DTO class Mapping (It IS a DTO and not a mapped entity, right?)


    Update: your SELECT statement needs a cast

    SELECT ...
           CAST(1 as bit) IsPrimaryName
    FROM ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.