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 6201615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:35:13+00:00 2026-05-24T04:35:13+00:00

I know so far that a local variable or a local property can be

  • 0

I know so far that a local variable or a local property can be used as an alias like so

ClassA _aliasA;
_session.QueryOver(x => x.ClassA, () => _aliasA);

or

ClassA AliasA { get; set; }
_session.QueryOver(x => x.ClassA, () => AliasA);

I want to know what other options are possible. Like, are properties of an external class a valid option?

class ClassGenericAliases
{
    ClassA Class { get; set; }
}

_session.QueryOver(x => x.ClassA, () => ClassGenericAliases.ClassA);

Can statics be used as aliases?
Are there other options for declaring aliases?

  • 1 1 Answer
  • 2 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-24T04:35:15+00:00Added an answer on May 24, 2026 at 4:35 am

    I would recommend never using anything for an Alias outside of the scope of the method that uses the alias.

    QueryOver is a strongly typed version of Criteria, in Criteria an alias was a string value.

    IList cats = sess.CreateCriteria(typeof(Cat))
        .CreateAlias("Kittens", "kt")
        .CreateAlias("Mate", "mt")
        .Add( Expression.EqProperty("kt.Name", "mt.Name") )
        .List();
    

    But now it needs to assign the alias to a variable so we just create one for it:

    Cat catAlias = null;
    Kitten kittenAlias = null;
    
    IQueryOver<Cat,Cat> catQuery =
        session.QueryOver<Cat>(() => catAlias)
            .JoinAlias(() => catAlias.Kittens, () => kittenAlias)
            .Where(() => catAlias.Age > 5)
            .And(() => kittenAlias.Name == "Tiddles");
    

    From NHForge documentation, it says the following:

    http://nhibernate.info/doc/nh/en/index.html#queryqueryover-aliases

    15.5. Aliases

    In the traditional ICriteria interface aliases are assigned using
    ‘magic strings’, however their value does not correspond to a name in
    the object domain. For example, when an alias is assigned using
    .CreateAlias(“Kitten”, “kittenAlias”), the string “kittenAlias” does
    not correspond to a property or class in the domain.

    In QueryOver, aliases are assigned using an empty variable. The
    variable can be declared anywhere (but should be null at runtime). The
    compiler can then check the syntax against the variable is used
    correctly, but at runtime the variable is not evaluated (it’s just
    used as a placeholder for the alias).

    Each Lambda Expression function in QueryOver has a corresponding
    overload to allow use of aliases, and a .JoinAlias function to
    traverse associations using aliases without creating a sub-QueryOver.

    So stick to just using a variable in the scope of the method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I know, in gcc you can write something like: #define DBGPRINT(fmt...)
The problem I'm running into is that as far as I know the delete
As far as I know document.getElementById('myId') will only look for HTML elements that are
As far as I know, foreign keys (FK) are used to aid the programmer
We all know you can't do things like this: int a = 7; new
As far as I know there are two ways to create local variables in
As far I know, the my operator is to declare variables that are truly
As far as know, I must be careful with PHP, and I think Javascript.
As far as I know, Flash has to pass info off to another external
As far as i know it is not possible to do the following in

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.