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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:26:52+00:00 2026-05-21T18:26:52+00:00

I have a mapping that I’m not quite sure how to do. I have

  • 0

I have a mapping that I’m not quite sure how to do. I have a table that has a Numeric(9,0) column with possible values of 0-3. I’d like to represent this as an enumeration within my entity but there isn’t a direct mapping of a Numeric(9, 0) to an integer. The reason it’s numeric is for cross-database support (MSSQL and Oracle).

Numeric(9,0) maps directly to a C# decimal which cannot be an enumeration. This is not one of the allowed types for an enumeration.

Would I need to leverage an IUserType in conjuction with an ITypeConvention here or is there another way? Also given the following mapping (LoginType is the type in question) how would I implement this IUserType?

public enum LoginType : int
{
    UNKNOWN = 0,
    COMPANY_LOGIN = 1,
    WINDOWS_LOGIN = 2,
    LDAP_LOGIN = 3
}

public class UserHeader
{
    public virtual Guid UserId { get; set; }
    public virtual LoginType LoginType { get; set; }
}
  • 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-21T18:26:52+00:00Added an answer on May 21, 2026 at 6:26 pm

    Try using the CustomType and CustomSqlType specifiers:

    public class UserHeaderMap:ClassMap<UserHeader>
    {
       public UserHeaderMap()
       {
          ...
          Map(x=>x.LoginType).CustomType(typeof(LoginType)).CustomSqlType("Numeric(9,0)");
       }
    }
    

    Specifying the custom type of the enumeration tells FNH to persist the numeric value, instead of its default behavior of persisting the ToString() value (and/or expecting it in the table). The CustomSqlType is more for schema generation purposes, overriding the default int type for the schema column.

    If that doesn’t work, try adding a Formula() instead of a CustomSqlType, to cast or convert the numeric to an int, which will be picked up by NH and cast to the enum value.

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

Sidebar

Related Questions

I have a mapping that looks like this: <class name=Record> <map name=Values> <key column=RecordFK/>
I have a Hibernate mapping that looks something like this: <class name=MyEntity> <set name=scalarSet
I have two tables that are related via a mapping table: keywords titles I
I have an xml mapping file that looks something like this <colourMappings> <model name=modelX>
I have set up a url mapping that goes like this: (r'enroll/$', 'enroll') In
In X/WebSiteMVC3/Core/DependencyResolution/XProfile.cs, I have an existing mapping that looks a little something like this:
I have a mapping in NHibernate that works like so: <?xml version=1.0 encoding=utf-8 ?>
I have a hierarchical JPA mapping that is several Classes deep. Something like this
I am using Struts 1.2.7 and have the standard servlet mapping that uses *.do
I have the following iBatis mapping for an Oracle Stored Procedure that returns a

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.