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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:36:34+00:00 2026-05-14T23:36:34+00:00

I’m storing some blobs in my database, so I have a Document table and

  • 0

I’m storing some blobs in my database, so I have a Document table and a DocumentContent table. Document contains a filename, description etc and has a DocumentContent property.

I have a Silverlight client, so I don’t want to load up and send the DocumentContent to the client unless I explicity ask for it, but I’m having trouble doing this.

I’ve read the blog post by Davy Brion. I have tried placing lazy=false in my config and removing the virtual access modifier but have had no luck with it as yet.

Every time I do a Session.Get(id), the DocumentContent is retrieved via an outer join. I only want this property to be populated when I explicity join onto this table and ask for it.

Any help is appreciated.

My NHibernate mapping is as follows:

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Jrm.Model"
                   namespace="Jrm.Model">
  <class name="JrmDocument" lazy="false">
    <id name="JrmDocumentID">
      <generator class="native" />
    </id>

    <property name="FileName"/>
    <property name="Description"/>
    <many-to-one name="DocumentContent" class="JrmDocumentContent" unique="true" column="JrmDocumentContentID" lazy="false"/>
  </class>


  <class name="JrmDocumentContent" lazy="false">
    <id name="JrmDocumentContentID">
      <generator class="native" />
    </id>

    <property name="Content" type="BinaryBlob" lazy="false">
      <column name="FileBytes" sql-type="varbinary(max)"/>
    </property>

  </class>
</hibernate-mapping>

and my classes are:

[DataContract]   
    public class JrmDocument : ModelBase
    {
        private int jrmDocumentID;
        private JrmDocumentContent documentContent;
        private long maxFileSize;
        private string fileName;
        private string description;

        public JrmDocument()
        {
        }

        public JrmDocument(string fileName, long maxFileSize)
        {
            DocumentContent = new JrmDocumentContent(File.ReadAllBytes(fileName));
            FileName = new FileInfo(fileName).Name;
        }

        [DataMember]
        public virtual int JrmDocumentID
        {
            get { return jrmDocumentID; }
            set
            {
                jrmDocumentID = value;
                OnPropertyChanged("JrmDocumentID");
            }
        }               

        [DataMember]
        public JrmDocumentContent DocumentContent
        {
            get { return documentContent; }
            set
            {
                documentContent = value;
                OnPropertyChanged("DocumentContent");
            }
        }        

        [DataMember]
        public virtual long MaxFileSize
        {
            get { return maxFileSize; }
            set
            {
                maxFileSize = value;
                OnPropertyChanged("MaxFileSize");
            }
        }


        [DataMember]
        public virtual string FileName
        {
            get { return fileName; }
            set
            {
                fileName = value;
                OnPropertyChanged("FileName");
            }
        }

        [DataMember]
        public virtual string Description
        {
            get { return description; }
            set
            {
                description = value;
                OnPropertyChanged("Description");
            }
        }
    }



    [DataContract]
    public class JrmDocumentContent : ModelBase
    {
        private int jrmDocumentContentID;
        private byte[] content;

        public JrmDocumentContent()
        {
        }
        public JrmDocumentContent(byte[] bytes)
        {
            Content = bytes;
        }

        [DataMember]
        public int JrmDocumentContentID
        {
            get { return jrmDocumentContentID; }
            set
            {
                jrmDocumentContentID = value;
                OnPropertyChanged("JrmDocumentContentID");
            }
        }

        [DataMember]
        public byte[] Content
        {
            get { return content; }
            set
            {
                content = value;
                OnPropertyChanged("Content");
            }
        }
    }
  • 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-14T23:36:35+00:00Added an answer on May 14, 2026 at 11:36 pm

    I had a problem with where my relationship was being managed (inverse=true) and also with my session instantiation as it was being injected in. Using that in conjunction with a custom DataContractSurrogate that prevented some of the lazy loading issues now works.

    Thanks

    var proxy = obj as INHibernateProxy; 
    if (proxy != null) 
    { 
        var initializer = proxy.HibernateLazyInitializer; 
        if (initializer.IsUninitialized) 
        { 
            return Activator.CreateInstance(obj.GetType().BaseType); } 
        else 
        { 
            return initializer.GetImplementation(); 
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.