Uploaded image for project: 'NHibernate'
  1. NHibernate
  2. NH-2132

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

    Details

      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_

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            pedroalvarado 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
            pedroalvarado 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 andrew grushewsky added a comment -

            Any workaround for this bug?

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

            Any fix or workaround ?

            Show
            paul Paul Jame added a comment - Any fix or workaround ?
            Hide
            andrew.grushewsky 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 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 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 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:
                pedroalvarado Pedro Alvarado
              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Who's Looking?