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

The Archive Base Latest Questions

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

I have a situation where I need to determine whether or not an inherited

  • 0

I have a situation where I need to determine whether or not an inherited class is a specific inherited class, but the type expected in the model is the base class, and it is stored using nHibernate/Fluent nHibernate using a Table Per Concrete Class Hierarchy. So my structure looks a bit like this..

class Mutation : Entity {
   virtual Aspect Aspect { get; set; }
   virtual Measurement Measurement { get; set; }
}

abstract class Measurement : Entity {
   // does nothing on its own, really.
}

class Numeric : Measurement {
   virtual int Value { get; set; }
   // may have some other properties
}

class Observable : Measurement {
  virtual Aspect Aspect { get; set; }
}

So basically, what is going on here is this. Mutation expects to be pointed to a type of data, and a Measured change (there could be other ways to change the data, not just flat numerics). So then I would have an object that merely expects an IList<Mutation> and map each subsequent type of Measurement to its own specific table, sharing the Identity with the base Measurement class. That works fine so far.

Now an Observable is different in that it does not store its own value, but rather it points again to another Aspect that may have its own set of mutations and changes. The idea is that the value will always be retrieved from the intended source, and not saved as a flat value in the database. (There is a reason for wanting this behavior that is beyond the scope of this question)

So then, my thought was basically to put in an evaluation like this ..

foreach(var measurement in list) {
   if(measurement is Observable){
      // then we know to lookup the other value
   }
}

That didn’t work. I still get the proxied result of just MeasurementProxy. But the same code works fine in a standalone C# application without the use of nHibernate, so I feel a great deal of confidence that the issue is with the proxy.

I then added the following method to my base Entity class…

        /// <summary>
        /// Unwrap the type from whatever proxy it may be
        /// behind, returning the actual .NET <typeparamref name="System.Type"/>.
        /// </summary>
        /// <returns>
        /// A pure <typeparamref name="System.Type"/> that is no longer proxied.
        /// </returns>
        public virtual Type Unwrap() {
            return GetType();
        } 

Now if I do a Console.WriteLine(measurement.Unwrap()); I get the right type, but the same evaluation …

foreach(var measurement in list) {
   if(measurement.Unwrap() is Observable){
      // then we know to lookup the other value
   }
}

still does not function. It never runs. Can anyone help me out here?

  • 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-23T19:51:02+00:00Added an answer on May 23, 2026 at 7:51 pm

    That’s because Unwrap() returns a Type, so measurement.Unwrap() is Observable will always be false, and measurement.Unwrap() is Type would always be true.

    Use the typeof operator and reference equality instead:

    if (measurement.Unwrap() == typeof(Observable)) {
        // Then we know to lookup the other value.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I need to determine if I've reached the end
I have situation where I need to change the order of the columns/adding new
I have a situation where I need to dynamically build up a list of
I have a situation where I need to pass two parameters to an action.
I have a situation where I need to update a control referenced in a
I have a situation where I need to notify some users when something in
I have a situation where I need to find the value with the key
I have a situation where i need to send commands to a running java
I have a situation where I need to concatenate several string to form an
We have a situation where we need to display data from a database 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.