NHibernate
  1. NHibernate
  2. NH-2132

Sql Server Dialect: Use of 'For XML' in formula attribute results in incorrect SQL.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.1.2.GA
    • Fix Version/s: None
    • Labels:

      Description

      Example:

      <property name="ChildQuestion" formula="(SELECT T.something from table T XML PATH(''))"/>

      Gets parsed as:

      (SELECT T.something FROM table T FOR entity0_.XML PATH('')) as formula0_2_
      as opposed to
      (SELECT T.something FROM table T FOR XML PATH('')) as formula0_2_

        Activity

        Hide
        Pedro Alvarado added a comment -

        In the description:

        <property name="ChildQuestion" formula="(SELECT T.something from table T XML PATH(''))"/>

        should read as:

        <property name="ChildQuestion" formula="(SELECT T.something from table T FOR XML PATH(''))"/>

        Show
        Pedro Alvarado added a comment - In the description: <property name="ChildQuestion" formula="(SELECT T.something from table T XML PATH(''))"/> should read as: <property name="ChildQuestion" formula="(SELECT T.something from table T FOR XML PATH(''))"/>
        Hide
        andrew grushewsky added a comment -

        Any workaround for this bug?

        Show
        andrew grushewsky added a comment - Any workaround for this bug?
        Hide
        Paul Jame added a comment -

        Any fix or workaround ?

        Show
        Paul Jame added a comment - Any fix or workaround ?
        Hide
        andrew grushewsky added a comment -

        I ended up with using my own interceptor. Looks like this:

        public class SQLFixInterceptor : EmptyInterceptor
        {
        public override SqlString OnPrepareStatement(SqlString sql)

        { return sql.Replace("for this_.xml", "for xml"); }

        }
        and using it in following way:
        var sessionFactory = Fluently.Configure()
        ...
        .BuildConfiguration()
        .SetInterceptor(new SQLFixInterceptor())
        .BuildSessionFactory();

        Show
        andrew grushewsky added a comment - I ended up with using my own interceptor. Looks like this: public class SQLFixInterceptor : EmptyInterceptor { public override SqlString OnPrepareStatement(SqlString sql) { return sql.Replace("for this_.xml", "for xml"); } } and using it in following way: var sessionFactory = Fluently.Configure() ... .BuildConfiguration() .SetInterceptor(new SQLFixInterceptor()) .BuildSessionFactory();
        Hide
        Paul Jame added a comment -

        Thanks, It worked...
        But I had to write like that :

        ...
        return sql.Replace("for myclass0_.xml", "for xml");
        ...

        So, To every different class that I need to use "for xml" am I supposed to add a new Replace ?

        Thanks

        Show
        Paul Jame added a comment - Thanks, It worked... But I had to write like that : ... return sql.Replace("for myclass0_.xml", "for xml"); ... So, To every different class that I need to use "for xml" am I supposed to add a new Replace ? Thanks

          People

          • Assignee:
            Unassigned
            Reporter:
            Pedro Alvarado
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:

              Who's Looking?