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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:07:57+00:00 2026-06-09T11:07:57+00:00

I need to create DTOs from NHibernate POCO objects. The problem is that the

  • 0

I need to create DTOs from NHibernate POCO objects. The problem is that the POCO objects contain dynamic proxies, which should not be copied to the DTO. I eager load all the collections and references I need to transfer in advance, I don’t want NHibernate to start loading referenced collections which I did not load in advance.

Several similar questions on SO received answers which either:

  1. Suggest Session.GetSessionImplementation().PersistenceContext.Unproxy();
  2. Suggest turning off Lazy Loading.

In my case the first suggestion is irrelevant, as according to my understanding it causes eager loading to replace the proxies. In reality, it doesn’t even work – it doesn’t remove the proxies in my objects. (Any explanation why?)

The second suggestion, turning off lazy loading seems to cause all references and collections to eager load, basically loading the entire DB. My expectation was that if lazy loading is off, and I have not requested a collection, it will not be loaded. (Am I correct that NHibernate offers no such option?)

I am using NHibernate 3.3.1 with fluent configuration.

To reiterate my main question, I need to create DTOs clean of proxies, copied from POCOs which contain proxies, and I don’t want to load the data behind those proxies.

Any helpful suggestion which includes example code and automates the process with ValueInjecter / AutoMapper will be immensely helpful.

Edit #1:

Following Roger Alsing’s suggestion to use projections, I realized that what I’m actually looking for is a ValueInjecter-like convention based mapping. Here is why. Initially, my DTOs will be defined the same as the model’s POCOs. This is due to a large code base which depends on the existing POCOs being transferred on the client-side project.

Using projections, I will have to specify which subset of fields have to be copied, and this subset may be different in each context (as, ideally, a DTO would differ). This will mean a lot of new code introduced to the server side, when there should be the second option.

Using ValueInjecter, I will be able to populate the DTOs by convention in one call, without writing specific projections, or having to maintain those into the future. That is, if I am able to have ValueInjecter ignore Proxy objects.

Given that using projections is a good but not ideal solution in my situation, is there a way to configure something like ValueInjecter to copy POCOs without copying proxies or triggering eager/lazy loads on copy?

  • 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-09T11:07:58+00:00Added an answer on June 9, 2026 at 11:07 am

    for ValueInjecter solution I recommend using SmartConventionInjection (you need to copy the code from the linked page into your solution)

    and after specify a convention that won’t touch the proxy properties

    here’s a start:

    public class MapPoco: SmartConventionInjection
    {
         protected override bool Match(SmartConventionInfo c)
         {
             return c.SourceProp.Name == c.TargetProp.Name;
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need create WebView which can load a page from Youtube. I don't want
I need create some fork for project. So for some beans that depends from
Problem I have various html tables that I need to parse/access from my customers
I need create clone repository. but I do not know where can I get
Need to create a custom DNS name server using C which will check against
I need to create a WP site which will have multiple subjects. Each subject
I'm using Visual Studio 2008 and I need create a DataTable from a Excel
i want to write head tag. i need create dynamic <head id=htmlHead runat=server> </head>
The image posted below is taken from a word document. I need create a
I create service and I need create class MyErrors (not exception) My web method

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.