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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:57:14+00:00 2026-05-22T19:57:14+00:00

I have a very strange issue that I cannot explain. I have my base

  • 0

I have a very strange issue that I cannot explain. I have my base mapping with this

//This will automatically cast the row into the correct object type based on the value in AccountType
DiscriminateSubClassesOnColumn<string>("AccountType")
            .Formula(String.Format("CASE AccountType WHEN {0} THEN '{1}' WHEN {2} THEN '{3}' ELSE '{4}' END", 
            (int)PaymentMethodType.CheckingAccount, 
            typeof(ACH).Name,
            (int)PaymentMethodType.SavingsAccount,
            typeof(ACH).Name,
            typeof(CreditCard).Name));

I have looked in the logs, I have executed the sql that nhibernate is generating, and all records have the same data. There is not difference in them that would denote why this should not work.

The base class is PaymentMethodBase. I have 2 subclasses, CreditCard and ACH, which inherit from PaymentMethodBase.

Then, I have this extension

public static string PaymentMethodName(this PaymentMethodBase paymentMethod)
{
        if (paymentMethod is ACH)
        {
            var ach = (ACH)paymentMethod;
            return String.Format("{0} {1}", ach.BankName, String.Format("XXXX{0}", ach.AccountNumber.Substring(ach.AccountNumber.Length - 4)));
        }

        if (paymentMethod is CreditCard)
        {
            var creditCard = (CreditCard)paymentMethod;
            return String.Format("{0} {1}", creditCard.Name, creditCard.CreditCardNumber);
        }

        return "Unknown Payment Method";
    }

Which I call like this.

public SelectList PaymentMethodsSelectList
{
    get
    {
        var methods = (from p in PaymentMethods
                       where p != null
                       select new
                       {
                           id = p.PaymentMethodId,
                           name = p.PaymentMethodName()
                       }).OrderBy(x => x.name);

        var results = methods.ToList();

        results.Insert(0, new { id = (int)NewPaymentMethods.ACH, name = "<New eCheck Account...>" });
        results.Insert(0, new { id = (int)NewPaymentMethods.CreditCard, name = "<New Credit Card...>" });

        return new SelectList(results, "id", "name");
    }
}

This code is used by 2 models. The collection of payment methods are all coming from the same object – a customer object. The collection is mapped like this.

HasMany<PaymentMethodBase>(x => x.PaymentMethods)
    .KeyColumn("CustomerId")
    .Where(y => y.AccountType < 10)
    .Inverse()
    .Cascade.All();

So, I get the customer 2 different ways. One is that I get the customer through another object (main site). The other has the object being pulled directly by id (in an iframe). The direct by id method works every time. The other method, where I get the customer through another object, causes only the first and last payment method to cast correctly. If there are more than 2, they are left in the base class and appear in the middle of the list after the sort.

I have tried changing the parent object to just mapping the id and then getting the customer record by the ID. Failure. There is something else in the way that is causing this to happen, but only on that one model.

  • 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-22T19:57:15+00:00Added an answer on May 22, 2026 at 7:57 pm

    I suspect that the issue here is Fetching issue.

    Since the extension method is running on the .Net side rather than in the “NHibernate level” it cannot run properly when the collection of payment methods is not available.

    Perhaps in the direct by Id methos you have Fetching set up for the payments whereas in the indirect method the automatic fetching goes only to the Customer object but stops short before fetching the Payment methods.

    Try to instruct NHibernate to pre-fetch the Payment methods for you in the indirect method.

    Something like:

    Session.Query<SomeObject>.Where(.....).Fetch(x => x.Customer).ThenFetch(c => c.PaymentMethods)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very strange issue that I'm hoping someone can help me with.
I have this very strange issue with my MVC 2 project. Often times, I'll
I have a very strange issue on my hands. I have two IIS websites
I have a very strange issue with Daylight Savings Time (DST) in my app.
We have very strange problem, one of our applications is continually querying server by
I have a very strange problem. Under some elusive circumstances I fail to apply
I have a very strange problem, when I try to var_dump (or print_r )
I have a very strange problem with the Delphi 2006 IDE. If the IDE
I have been noticing some very strange usage of O(1) in discussion of algorithms
i have very simple problem. I need to create model, that represent element of

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.