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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:13:51+00:00 2026-05-23T11:13:51+00:00

I have a data source that supports querying based on several identifiers. These identifiers

  • 0

I have a data source that supports querying based on several identifiers. These identifiers are abstracted by an IIdentifier class that wraps the type and value for the query. In my NHibernate DAO, I have the following method.

public IEnumerable<ICustomerProfileAttribute> GetCustomerProfileAttributes(
    IIdentifier<CustomerIdentifierTypeEnum> identifier, IEnumerable<string> attributeNames)
{
    IList<ICustomerProfileAttribute> customerProfileAttributes = new List<ICustomerProfileAttribute>();

    ICustomerProfile customerProfileAlias = null;
    ICustomerProfileAttribute customerProfileAttributeAlias = null;
    IEntityTypeAttribute entityTypeAttribute = null;
    IAttribute attributeAlias = null;

    Expression<Func<bool>> findCustomerProfileQuery;
    // I would like to replace the switch with something like this:
    // = FindCustomerProfileExpressionFactory.Get(customerProfileAlias, identifier); 

    switch (identifier.IdentifierType)
    {
        case CustomerIdentifierTypeEnum.CustomerNumber:
            findCustomerProfileQuery = () => customerProfileAlias.CustomerNumber == identifier.Value.ToString();
            break;
        case CustomerIdentifierTypeEnum.WebAccount:
            findCustomerProfileQuery = () => customerProfileAlias.WebAccountId == (long)identifier.Value;
            break;
        case CustomerIdentifierTypeEnum.WebLogin:
            findCustomerProfileQuery = () => customerProfileAlias.LoginEmailAddress == identifier.Value.ToString();
            break;
        default:
            throw new NotImplementedException(String.Format("lookup of customer profiles using {0} is not supported", identifier.IdentifierType));
    }

    return Session.QueryOver(() => customerProfileAttributeAlias)
        .JoinAlias(() => customerProfileAttributeAlias.CustomerProfile, () => customerProfileAlias,
                    JoinType.LeftOuterJoin)
        .Where(findCustomerProfileQuery)
        .JoinAlias(() => customerProfileAttributeAlias.EntityTypeAttribute, () => entityTypeAttribute,
                    JoinType.LeftOuterJoin)
        .JoinAlias(() => entityTypeAttribute.Attribute, () => attributeAlias, JoinType.LeftOuterJoin)
        .Where(Restrictions.On(() => attributeAlias.Name).IsIn(attributeNames.ToArray()))
        .List<ICustomerProfileAttribute>();
}

I would like to extract the switch statement into a factory class, as it would be useful in several other parts of my application. I tried the following:

class FindCustomerProfileExpressionFactory
    {
        static public Expression<Func<bool>> Get(ICustomerProfile profile, IIdentifier<CustomerIdentifierTypeEnum> identifier)
        {
            switch (identifier.IdentifierType)
            {
                case CustomerIdentifierTypeEnum.CustomerNumber:
                    return () => customerProfileAlias.CustomerNumber == identifier.Value.ToString(); 
             ...

However, by referencing the factory class, I am aliasing the local variable into the lambda expression, leading to the following error:

NHibernate.QueryException: could not resolve property: profile of: CustomerProfile.Domain.CustomerProfileAttribute

Is there a way to generate an expression that refers to a a local variable? Could I use a parameterized expression with that Where clause? Any other solutions?

  • 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-23T11:13:52+00:00Added an answer on May 23, 2026 at 11:13 am

    I eventually figured out the answer. It seems as if NHibernate uses the name of the variables in the QueryOver expressions somehow in its code. I changed the parameter name in my factory to match the variable name in the method, and it worked!

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

Sidebar

Related Questions

I have a data source on a Windows machine that supports an ODBC connection.
I have a data source with about 2000 lines that look like the following:
I have a repeater that's bound to a SQL Data Source (using ASP.NET). Are
I have a small application that uses a SharePoint list as the data source.
I have a C program that mines a huge data source (20GB of raw
I have a data frame in R that looks like this: > TimeOffset, Source,
I have a Django app that gets it's data completely from an external source
So I have learned that that the Microsoft.Jet.OLEDB.4.0 data provider for querying data sources
I have a data object used to contain my UI data that supports INotifyPropertyChanged
If one wants to paginate results from a data source that supports pagination we

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.