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

  • Home
  • SEARCH
  • 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 4066584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:08:47+00:00 2026-05-20T16:08:47+00:00

I’ve got an application witch uses NHibernate as an ORM. I have one persistent

  • 0

I’ve got an application witch uses NHibernate as an ORM. I have one persistent class:

public class Match : IEntity
{
    public virtual int ID { get; set; }
    public virtual string Word { get; set; }
    public virtual int WordIntervalBeginning { get; set; }
    public virtual int WordIntervalEnding { get; set; }
}

and I have an SQL function on the server side:

CREATE FUNCTION ftMatchTest
( )
RETURNS TABLE 
AS
RETURN 
(
    SELECT mt1.*, mt2.*,
    CASE WHEN mt1.Word = mt2.Word THEN 1 ELSE 0 END AS sc
    FROM
        dbo.tMatchesTest mt1, dbo.tMatchesTest mt2
)

I want to be able to call this function and map the result from it into the following class

public class FResult
{
    public Match Match1 { get; set; }
    public Match Match2 { get; set; }
    public int sc { get; set; }
}

Is it possible to do it with NHibernate 3.0? Is it possible to do it with FluentNHibernate?
Thanks in advance!

UPDATED
I map Match class into tMatchesTest table.
Structure of tMatchesTest table is:

CREATE TABLE [dbo].[tMatchesTest](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Word] [varchar](50) NOT NULL,
    [WordIntervalBeginning] [int] NOT NULL,
    [WordIntervalEnding] [int] NOT NULL,
 CONSTRAINT [PK_tMatchesTest] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

UPDATED2
The solution I found on my own:
1. Create named query like this

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
                   namespace=" ConsoleApplication8.Domain.Entities"
                   assembly="ConsoleApplication8">

  <resultset name="fresult-resset">
    <return alias="Match1" class="Match"/>
    <return alias="Match2" class="Match"/>
    <return-scalar column="sc" type="int"/>
  </resultset>


  <sql-query name="getfresult" resultset-ref="fresult-resset">
    SELECT {Match1.*}, {Match2.*},
    CASE WHEN Match1.Word = Match2.Word THEN 1 ELSE 0 END sc
    FROM dbo.tMatchesTest Match1, dbo.tMatchesTest Match2
  </sql-query>

</hibernate-mapping>

and execute the query like this:

Session.GetNamedQuery("getfresult")
                .SetResultTransformer(new AliasToBeanResultTransformer(typeof(FResult)))
                .List<FResult>();

This is the shortest and simples way I found so far to perform the task.

  • 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-20T16:08:48+00:00Added an answer on May 20, 2026 at 4:08 pm

    IResultTransformer is used to transform query results into a application-visible types.

    Also, mapping the SQL function call as a named SQL query will give cleaner code.

    var list = Session.GetNamedQuery("ftMatchTest")
        .SetResultTransformer(new AliasToFResultTransformer())
        .List<FResult>();
    

    Since we have a multi-table result, AliasToBeanResultTransformer is not directly usable. Instead we will subclass it and convert the result to the desired type.

    public class AliasToFResultTransformer : AliasToBeanResultTransformer
    {
        public AliasToFResultTransformer() : base(typeof(FMatches)) {}
    
        object IResultTransformer.TransformTuple(object[] tuple, string[] aliases)
        {
            FMatches fm = base.TransformTuple( tuple, aliases ) as FMatches;
    
            return fm.ToFResult();
        }
    
        public class FMatches
        {
            public int sc { get; set; }
            public virtual int Mt1ID { get; set; }
            public virtual string Mt1Word { get; set; }
            public virtual int Mt1WordIntervalBeginning { get; set; }
            public virtual int Mt1WordIntervalEnding { get; set; }
            public virtual int Mt2ID { get; set; }
            public virtual string Mt2Word { get; set; }
            public virtual int Mt2WordIntervalBeginning { get; set; }
            public virtual int Mt2WordIntervalEnding { get; set; }
    
            public FResult ToFResult()
            {
                return new FResult {
                    sc = this.sc,
                    Match1 = new Match {
                        Id = this.Mt1Id,
                        Word = this.Mt1Word,
                        WordIntervalBeginning = this.Mt1WordIntervalBeginning,
                        WordIntervalEnding = this.Mt1WordIntervalEnding
                    },
                    Match2 = new Match {
                        Id = this.Mt2Id,
                        Word = this.Mt2Word,
                        WordIntervalBeginning = this.Mt2WordIntervalBeginning,
                        WordIntervalEnding = this.Mt2WordIntervalEnding
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
I have just tried to save a simple *.rtf file with some websites and
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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

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.