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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:10:52+00:00 2026-06-13T00:10:52+00:00

With lazy loading configured, I run into an issue regarding object comparison. My overriden

  • 0

With lazy loading configured, I run into an issue regarding object comparison. My overriden Equals-method within each domain entity class contains the following line:

if (obj == null || !obj.GetType().Equals(GetType()))

Obviously, The type comparison will fail as obj is a proxy instance. I’ve already seen some NHibernate-snippets which unproxy an object and return the real instance. But as I enforce a domain driven design, I do not want any ORM-specific code within my domain layer.
I also cannot unproxy the instance on caller side [e.g. foo.Equals(Unproxy(bar))] as the caller is my application layer which also doesn’t contain any ORM-specific code (all NHibernate dependencies are injected by Windsor).

Long story short: is there any generic code to get the real instance?

  • 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-06-13T00:10:54+00:00Added an answer on June 13, 2026 at 12:10 am

    The way to solve that is to do a cast:

    public class Person
    {
        public int Id { get; set; }
    
        public override bool Equals(object obj)
        {
            var person = obj as Person;
    
            if (person == null)
            {
                return false;
            }
    
            return person.Id == this.Id;
        }
    }
    

    The cast works because the proxy inherits from your class (e.g. PersonProxy : Person)

    The null check is unnecessary as the as cast will just return null if obj is either null or not an object that can be cast as a person.

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

Sidebar

Related Questions

We're using an asp:TreeView configured with lazy loading. The callback method assigned for OnTreeNodePopulate
I am lazy loading an image via setImageWithURL into a UIImageView embedded in a
I'm trying to implement lazy loading on a blogger blog, but I'm running into
I'm doing some lazy loading of images into an array when the app has
I'm lazy loading images from the web and tossing them into UIImageViews that I
I'm trying to create a lazy loading method using Java Lists that takes in
I'm trying to avoid hibernate's lazy-loading mechanism and I've created this list object with
I just configured @PersistenceContext(type=PersistenceContextType.EXTENDED) on my DAO classes to get lazy loading working on
Scenario: I have a customer object with lazy loading enabled. I use that throughout
I have problem with lazy loading in many-to-many. There is no exception and there

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.