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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:07:35+00:00 2026-05-13T15:07:35+00:00

Why are the entity class methods declared as public virtual, when the class is

  • 0

Why are the entity class methods declared as public virtual, when the class is to be mapped with a table using NHibernate.

Is the answer that NHibernate will be able to override these methods at runtime?

  • 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-13T15:07:35+00:00Added an answer on May 13, 2026 at 3:07 pm

    NHibernate requires this by default because it generates a proxy for your class, to support lazy loading of the entity (not to be confused with lazy loading of associated entities or collections).
    When loading an entity from the DB using NHibernate’s ‘ISession.Load’ method, NHibernate will return a proxy for that entity, which means that it returns an empty entity, where only the primary key (identifier) is set. The values of the other properties are only retrieved once you actually read a property.

    However, you can disable this behaviour. In your NHibernate mapping, you can specify that no dynamic proxies should be used by NHibernate for an entity. This is fairly simple to do, you just have to specify lazy=”false” on the class – mapping:

    MyEntity.hbm.xml:

    <class name="MyEntity" table="MyTable" lazy="false">
    </class>
    

    By doing this, you do not have to declare virtual properties or methods.
    I mostly do it this way, since I don’t wan’t to declare properties or methods as virtual, if my domain model doesn’t require this. I can live with the -imho- minimal performance hit of not using dynamic proxies.

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

Sidebar

Ask A Question

Stats

  • Questions 306k
  • Answers 306k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't render a partial inside of JavaScript to detect… May 13, 2026 at 9:12 pm
  • Editorial Team
    Editorial Team added an answer There are performance improvements that might see with 64-bit. A… May 13, 2026 at 9:12 pm
  • Editorial Team
    Editorial Team added an answer Try: .class { min-width: 550px; width: 75%; } May 13, 2026 at 9:12 pm

Related Questions

I have a Linq object, and I want to make changes to it and
Is using the 'synchronized' keyword on methods in a Java DAO going to cause
We've just separated our SQL Server database adapters to allow for differences between SQL
I'm getting an NHibernate.DuplicateMappingException that I don't understand. The app is a simple project
As I mention in an earlier question, I'm refactoring a project I'm working on.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.