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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:56:56+00:00 2026-05-30T11:56:56+00:00

Let’s say I have a product class that has a Category property on it.

  • 0

Let’s say I have a product class that has a Category property on it.

public class Product : Entity<int> // Base class defines the Id
{
  public virtual ProductCategory Category { get; set; }
}

The mapping file is simple

public class ProductMap : ClassMap<Product>
{
  public ProductMap()
  {
    Id(x => x.Id);
    References(x => x.Category).Nullable();
  }
}

Using SchemaExport.Create This created two columns in my database, ProductCategoryId and CategoryId. Given my conventions, only CategoryId should exist. Both are nullable, but only CategoryId is used. No matter what, ProductCategoryId is always null, and it is the column with the foreign key constraint on it.

Why is this? I can’t actually find any problems with the code, as far as I can tell everything works fine using the CategoryId column. I can query/save/update with or without a Category. I wouldn’t even know the other column existed if I didn’t go looking in the database, but I don’t like having a column when I don’t know what it is for. Is there a reason it is there, or is something wrong with the way I mapped a nullable reference?

  • 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-30T11:56:58+00:00Added an answer on May 30, 2026 at 11:56 am

    Well the problem isn’t anything to do with the Product or ProductMap class I believe. The issue is with the ProductCategory map.

    That is what is creating the ProductCategoryId column in the database.

    public class ProductCategoryMap : ClassMap<ProductCategory>
    {
        public ProductCategoryMap()
        {
            Id(x => x.Id);
            // Other mappings
            HasMany(x => x.Products).Inverse().Cascade.AllDeleteOrphan();
        }
    }
    

    This mapping wasn’t able to tell that it was supposed to be using the existing CategoryId column. Specifying it on the mapping file, or even renaming my Category property on the Product class to ProductCategory forces it to stop creating a different column.

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

Sidebar

Related Questions

Let's say I have a Cat that has two properties: FavoriteKitten SecondFavoriteKitten These kittens
let's say i have this public class MyClass { public string myMessage { get;
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say that I have a model that handles recipes, and I want to
Let's suppose we have: Class Foo{ int x,y; int setFoo(); } int Foo::setFoo(){ return
Let's imagine I have a Java class of the type: public class MyClass {
Let's say that I have a set of relations that looks like this: relations
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting

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.