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

  • Home
  • SEARCH
  • 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 7646643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:15:40+00:00 2026-05-31T10:15:40+00:00

If this is the way for hard-coded mapping for nullable and not nullable database

  • 0

If this is the way for hard-coded mapping for nullable and not nullable database fields

// nullable
Map(x => x.FirstName)
  .Nullable();

// not nullable
Map(x => x.FirstName)
  .Not.Nullable();

How is it done with automapping and conventions?

Also, it is not obvious but the purpose that I need it for is to have nhibernate generate insert sql statements without using a primary key field.

Example:
if I want database to generate ProductId, instead of

insert into Product (ProductId, Name) values (1, 'product name');

NHibernate should generate

insert into Product (Name) values ('product name');

And, rdbms should not be a question here, as a client code should not care how database assigns it.

  • 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-31T10:15:41+00:00Added an answer on May 31, 2026 at 10:15 am

    After all, solution is in implementing IIdConvention interface. I’m adding some code in case someone find this useful.

    public class PrimaryKeyConvention : IIdConvention
    {
        public void Apply(IIdentityInstance instance)
        {            
            instance.Column(instance.EntityType.Name + "Id");
            instance.GeneratedBy.Native();
        }
    }
    

    It can even be used with custom class for generating id

    public class PrimaryKeyConvention : FluentNHibernate.Conventions.IIdConvention
    {
        public void Apply(IIdentityInstance instance)
        {            
            instance.Column(instance.EntityType.Name + "Id");
            instance.GeneratedBy.Custom(typeof(CustomIdGenerator));
        }
    }
    public class CustomIdGenerator : NHibernate.Id.IIdentifierGenerator
    {
    
        public object Generate(NHibernate.Engine.ISessionImplementor session, object obj)
        {
            return null; //this should be custom implemented
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just learnt (the hard way) that databinding doesn't work with fields. This isn't
Mine is this: Hard coding is the way! All my problems go away. Just
Having a hard time figuring out the best way to do this... I have
Hello I am having a hard time making this UI element look the way
I often use webservice this way public void CallWebservice() { mywebservice web = new
Why was C# designed this way? As I understand it, an interface only describes
I followed this way. To create a workspace to manage your source-controlled files 1.
I added the legend this way: leg = fig.legend((l0,l1,l2,l3,l4,l5,l6), ('0 Cl : r2, slope,
This is the first time I have manipulated hashes and arrays in this way
I'm using the Python Shell in this way: >>> s = 'Ã' >>> s

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.