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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:57:04+00:00 2026-05-15T06:57:04+00:00

I am creating a message queue in a database. Each queued item stores a

  • 0

I am creating a message queue in a database. Each queued item stores a ID and a couple of other things. But the key field is IncomingMessage. In the database I am storing a serialized version of the IncomingMessage because it can be one of a number of types (like NewWorkorderMessage or EmployeeStatusChangeMessage). So the field in my QueuedMessage class _incomingMessage is a string.

However, I would like to avoid the usual required public virtual string QueuedMessage{get;set;} business and simply have a public object GetMessage() and public SetMessage(object message) method to deal with automatically serialized the .NET class in to the XML. Naturally the calling application wants to deal with instances of Message classes, not XML that it has to serialize/deserialize.

Using FluentNHibernate I’m not sure how to do this. I’ve tried a couple of different approaches such as the following, but this still requires me to have the property.

Any ideas? Thanks.

            Map(x => x.IncomingMessage)
            .Not.Nullable()
            .WithLengthOf(3000)
            .Access.AsReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore);
  • 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-15T06:57:05+00:00Added an answer on May 15, 2026 at 6:57 am

    Well, I’ve done something similar with Images. I store images as blobs in the DB, but want to access them as Image classes on my POCO classes. I did this by using the IPropertyAccessor interface.

    My Fluent NHibernate looks like this

            Map(entity => entity.Image)
                .Access.Using<ImagePropertyAccessor>()
                .Nullable();
    

    and my IPropertyAccessor looks like this:

    public class ImagePropertyAccessor : IPropertyAccessor
    {
        #region Setter
    
        private class ImageGetterSetter : IGetter, ISetter {
            PropertyInfo _property;
            ImageFormat _imageFormat;
            public ImageGetterSetter(PropertyInfo property, ImageFormat imageFormat)
            {
                if (property == null) throw new ArgumentNullException("property");
                if (property.PropertyType != typeof(Image)) throw new ArgumentException("property");
                _property = property;
                _imageFormat = imageFormat;
            }
    
            public void Set(object target, object value) {
                var image = Deserialise((byte[]) value);
                _property.SetValue(target, image, null);
            }
    
            public object Get(object target)
            {
                var image = (Image)_property.GetValue(target, null);
                var data = Serialise(image);
                return data;
            }
    
            private byte[] Serialise(Image image)
            {
                if (image == null)
                    return null;
                var ms = new MemoryStream();
                image.Save(ms, _imageFormat);
                return ms.ToArray();
            }
    
            private Image Deserialise(byte[] data)
            {
                if (data == null || data.Length == 0)
                    return null;
                var ms = new MemoryStream(data);
                return Image.FromStream(ms);
            }
    
            public object GetForInsert(object owner, IDictionary mergeMap, ISessionImplementor session)
            {
                return Get(owner);
            }
    
            public Type ReturnType
            {
                get { return typeof (byte[]); }
            }
    
            public string PropertyName {
                get { return _property.Name; }
            }
    
            public MethodInfo Method {
                get { return null; }
            }
        }
    
        #endregion
    
        public IGetter GetGetter(Type theClass, string propertyName) {
            return new ImageGetterSetter(theClass.GetProperty(propertyName), ImageFormat.Bmp);
        }
    
        public ISetter GetSetter(Type theClass, string propertyName) {
            return new ImageGetterSetter(theClass.GetProperty(propertyName), ImageFormat.Bmp);
        }
    
        public bool CanAccessThroughReflectionOptimizer {
            get { return false; }
        }
    }
    

    What I do not know, or rather have not investigated, is the effect of pushing the serialisation/deserialisation into NHibernate. Obviously there is an extra overhead associated with this. In my example it’s not too bad, as I’m not dealing with masses of entities and data. For performance reasons you may be better having a deserialised string and exposing your own methods to convert this. But the IPropertyAccessor is good for preserving the design of your POCO classes.

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

Sidebar

Ask A Question

Stats

  • Questions 430k
  • Answers 430k
  • 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 hmm, fwiw, this seems to work. module ActiveRecord class Base… May 15, 2026 at 1:55 pm
  • Editorial Team
    Editorial Team added an answer Because comparing integers is much faster than comparing strings and… May 15, 2026 at 1:55 pm
  • Editorial Team
    Editorial Team added an answer Well, the short answer is "because that's the way the… May 15, 2026 at 1:55 pm

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.