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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:37:16+00:00 2026-05-16T23:37:16+00:00

I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate’s auto

  • 0

I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate’s auto mapping feature for its data access. I have encountered a scenario in which I would like NHibernate to persist some classes as binary data.

For example, I have something similar to this:

public class User
{
    ...

    // This field will be persisted
    public virtual byte[] PortraitData { get; set; }

    // This method will get me what I'm actually interested in
    public virtual Image GetPortrait()
    {
        return SerializationHelper.Deserialize<Image>(PortraitData);
    }
}

(I leave the implementation of the SerializationHelper class to the reader’s imagination. It doesn’t do anything complicated, just serializes and deserializes data into byte arrays and back.)

I would like to change the above code to this:

public class User
{
    ...

    public virtual Image Portrait { get; set; }
}

So basically I wish to tell (Fluent)NHibernate that it should persist some classes (specified by me) by serializing them into a binary field with the name of the actual property.
(In the above case, I would like it to serialize the Image into a varbinary field called Portrait.)

The actual scenario I have is a bit more complicated than this, but this example demonstrates very well what I want to achieve. (Meaning: the System.Drawing.Image class is not the only one I’m interested in serializing.)

I know there must be some kind of configuration in either Fluent or NHibernate itself that allows to do exactly this, but I couldn’t figure it out. Could you please tell me how to do this?

Thanks in advance for your help!

  • 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-16T23:37:18+00:00Added an answer on May 16, 2026 at 11:37 pm

    The key is an implementation of IUserType, which is essentially an interface you use to translate back and forth from a POCO type to a SQL type. I use it to translate enumerations <-> custom string values in the database. Take a look at the NHibernate code for YesNoType, which translates back and forth between true/false booleans POCO types to “YES”/”NO” SQL varchar types.

    To utilize this in Fluent NHibernate, you can invoke the .CustomType() method on the Map method, where T is the class that implements IUserType. I think you could create a convention such that all Image properties would use the implementing class, rather than having to define it on a per-property basis, but I’m not familiar with that part of Fluent NHibernate.

    e.g. Map(x => x.Portrait, “PORTRAIT_DATA”).CustomType();

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

Sidebar

Related Questions

I have written a simple ASP.NET MVC 2 application that stores data and can
I have an ASP.NET MVC application that currently uses the WebClient class to make
I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which
I have a pretty simple ASP.NET Web Form that looks a bit like the
We have a very simple ASP.NET web application comprising mostly static content and a
I have an asp.net Web Forms application that needs to send emails. I like
I am developing an asp.net mvc web application that makes much use of jquery
I have an ASP.Net MVC 3 web application and I am adding a check
I have a web application written in ASP.NET MVC 3 . This application have
I have an ASP.NET MVC web application which is hosted by an external provider,

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.