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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:09:45+00:00 2026-06-14T03:09:45+00:00

When exactly does NHibernate convert a collection that, while the Session is open is

  • 0

When exactly does NHibernate convert a collection that, while the Session is open is represented as a PersistentGenericBag, but later on is converted back to the IList that I defined in my source code?

I thought it was when either the transaction was committed, or the session was disconnected. But I’m writing a unit test and no matter how many things I close, flush, commit and disconnect, my object always has a PersistentGenericBag, not a List.

Thanks

  • 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-14T03:09:46+00:00Added an answer on June 14, 2026 at 3:09 am

    Do not get me wrong. But do you really have mapping like this?

    public class MyObject 
    {
        public virtual List<string> MyColl { get; set; }
    }
    

    Because my experience says, that this will end up in exception like this:

    NHibernate.PropertyAccessException: Invalid Cast (check your mapping for property type mismatches);
    setter of MyLib.MyObject ---> System.InvalidCastException: Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag'1[System.String]' to type 'System.Collections.Generic.List
    1[System.String]`

    What I would expect inside your mapping is IList<>. Because exactly this will allow the NHibernate to inject its own implementation of it. Namely: PersistentGenericBag

    public class MyObject 
    {
        public virtual IList<string> MyColl { get; set; }
    }
    

    And in that case, the answer is: never. The proxy of MyObject provides all functionality published by IList<> while still working with property of type PersistentGenericBag

    And when is it really populated? when firstly accessed (via getter). Inner implementation of PersistentGenericBag will execute sql query and load data into internal IList<>. Of course session have to be still opened and connected to MyObject

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

Sidebar

Related Questions

What exactly does SignedCookieJar do? And what is the difference from that and using
What exactly does execve() do? I've tried looking at the documentation (http://linux.die.net/man/2/execve) but given
What exactly does an operating system do? I know that operating systems can be
What exactly does this instruction do? I know that it tries to align data
What exactly does this mean? I've seen Availability: iOS (6.0 and later) and other
What exactly does the EntityFramework do to map properties that have custom getters and
What exactly does immutable mean - that is, what are the consequences of an
It seems that altough I have been using NHibernate for a while now, I
What exactly does this mean -- Maybe IRB bug!? What does that tell me
How exactly does adding a random number to the end of an AJAX server

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.