0

I have the following entities, mapped by code:

VarRecipeMapping.cs

public VarRecipeMapping()
{
    Table("var_recipe");

    // ...

    Bag(x => x.Entries, m =>
    {
        m.Cascade(Cascade.All | Cascade.DeleteOrphans);
        m.Lazy(CollectionLazy.NoLazy);
    },
    a => a.OneToMany());
}

VarRecipeEntryMapping.cs

public VarRecipeEntryMapping()
{
    Table("var_recipe_entry");

    // ...

    ManyToOne(x => x.Recipe, m =>
    {
        m.Column("var_recipe_id");
        m.NotNullable(true);
    });
}

What annoys me is the resulting database (SQLite): it contains all columns of my entites defined by Column plus an additional, unused Recipe column in the var_recipe_entry table.

Obviously generated by NHibernate due to having a field called Recipe in the model.

What can I do to get rid of this useless field?

kagmole
  • 2,005
  • 2
  • 12
  • 27

1 Answers1

0

Found it.

I had to specify the custom name on the "one-to-many" side too.

VarRecipeMapping.cs

public VarRecipeMapping()
{
    Table("var_recipe");

    // ...

    Bag(x => x.Entries, m =>
    {
        // The custom name needs to be specified here too
        m.Key(n => {
            n.Column("var_recipe_id");
        });

        m.Cascade(Cascade.All | Cascade.DeleteOrphans);
        m.Lazy(CollectionLazy.NoLazy);
    },
    a => a.OneToMany());
}

VarRecipeEntryMapping.cs

public VarRecipeEntryMapping()
{
    Table("var_recipe_entry");

    // ...

    ManyToOne(x => x.Recipe, m =>
    {
        m.Column("var_recipe_id");
        m.NotNullable(true);
    });
}
kagmole
  • 2,005
  • 2
  • 12
  • 27