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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:45:32+00:00 2026-05-30T12:45:32+00:00

I have a scenario where a class called Comment references an abstract type called

  • 0

I have a scenario where a class called “Comment” references an abstract type called “Entity”. The Fluent-ClassMap looks quite similar to the following for the property “Entity”:

classMap.ReferencesAny(x => x.Entity)
   .EntityTypeColumn("DiscriminatorType")
   .EntityIdentifierColumn("DiscriminatorId")
   .IdentityType<int>()
   .AddMetaValue(typeof(Car), typeof(Car).Name);
   .AddMetaValue(typeof(House), typeof(House).Name);

As you might have already discovered from the example above the class “Entity” is subclassed by a class named “House” and a class called “Car”. With this setup it is rather trivial to retrieve all comments for a specifc “Entity” by simply doing something like the following: Session.Query().Where(m => m.Entity == myCarObject).ToList(). Everything works like a charm.

Here is the simplified class structure:

abstract class Entity{}
class Car : Entity{}
class House : Entity{}

class Comment 
{ 
  public virtual Entity { get; set;}
}

However, in one use case I need to retrieve all instances of “Comment” that reference any “Car”. In other words I’m trying to achieve something like the following:

var allCommentsOnCars1 = Session.Query<Comment>().Where(m => m.Entity is Car); //or
var allCommentsOnCars2 = Session.Query<Comment>().Where(m => m.Entity.GetType() == typeof(Car));

Both examples are not working (the latter throws a GetType() is not implemented exception), but is it possible to solve this anyhow? Very likely I could easily clear my problems by creating two seperate tables: One for all the “Cars” comments as well as one for all the “Houses” comments, but I would rather not change the database structure nor the models at this moment.

Your feedback would be greatly appreciated.

  • 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-30T12:45:33+00:00Added an answer on May 30, 2026 at 12:45 pm

    Probably not the most elegant solution, but I solved the problem by simply using QueryOver() instead of Query().

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

Sidebar

Related Questions

My Scenario I have a class library that is going to be called from
I have a similar scenario as this one: public class TestLinq2Xml { private XElement
I have the following scenario, class foo { ... private: char *_test; }; void
I have a very simple scenario, using NHibernate: one abstract base class animal; two
Scenario: I have the following defined classes. class Baseclass { }; class DerivedTypeA :
I'm using Automapper and I have the following scenario: Class OrderModel has a property
Ok, I have this scenario. A class called a which includes windows.h. #ifndef a.h
I have the following scenario: At onClick() event 2 javascript functions are called, each
Here's the scenario: I'd like to have a host class that can have a
I have the following scenario: Class_A - method_U - method_V - method_X - method_Y

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.