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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:04:11+00:00 2026-05-27T05:04:11+00:00

I have ~40 classes, and they all implement an interface IEntity. Of the ~40

  • 0

I have ~40 classes, and they all implement an interface IEntity.

Of the ~40 classes, many use a “Many-To-One” mapping to an IEntity property. An example of this could be:

"IEntity.cs"
public interface IEntity
{
   Guid ID
   ...Other properties (~7 of them)
}

"Item.cs"
public class Item : IEntity
{

   Public Guid ID {get;set;}
   ...Other IEntity Properties

   Public IEntity Owner {get;set;}  

}

I believe to use NHibernate to map the Owner property on Item, I will need to use one of NHibernate’s inheritance mappings using IEntity as a base.

The issue is that configuration of the 2nd level cache is tied to a class definition, not to the subclasses. I would have to turn on caching on all ~40 classes in my model at one time, and I wouldn’t be able to just cache the classes I want, such as categories.

Does anyone know how I can map an entity that has a property that is the type of an abstract entity without losing the ability to make 2nd level cache choices?

  • 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-27T05:04:12+00:00Added an answer on May 27, 2026 at 5:04 am

    firstly, I’m not sure I really get the idea of defining properties’ type as IEntity– are you sure it’s okay for Item to be the owner of another item? is it okay for an Employee to be the owner of an item?
    If the answer is yes, and that’s the business logic of your system, then there’s nothing to do about this.
    Otherwise- you may find it helpful to define an IOwner or even a OwnerBase base class to help with that distinction.
    This may also be helpful with ditinguishing which classes to cache and which not to.

    And now to the caching question:

    the definition of 2nd level cache needs to occur in two places:
    1. The class’s mapping
    2. The association mapping

    in your case, I believe you would indeed have to turn on 2nd level cache for all the IEntity classes. But if you only turn on the caching for specific associations, then only those associations would be cached.
    (an exception to this is using Get<T>() or Load<T>() methods, which would also cause your objects to be cached. If I’m not mistaken, you can tell nHib not to use the cache for specific queries)

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

Sidebar

Related Questions

I have developed some classes with similar behavior, they all implement the same interface.
If I have some classes that implement the same interface, so they all contain
I have the following situation: Three concrete service classes implement a service interface: one
I have several classes that conceptually belong to one tier. They have no common
I have an interface called ICommand from which various classes inherit. These classes all
I have a business model with many classes in, some logical entities within this
I have multiple Linq2Sql Classes such as Article NewsItem Product. They all have a
I have downloaded a third party library and they have classes I need to
I have classes which have automatic properties only like public customerName {get; set;}. They
I am communicating with a partner's webservice using proxy classes they've provided. I have

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.