0

I have a couple of classes that look like this:

public class Client
{
    public int Id {get;set;}
    public string Name {get;set;}
}

public class User
{
    public int Id {get;set;}
    public string Email {get;set;}
    public Client Client {get;set;}
}

I'm using ConventionModelMapper and SchemaUpdate from NHibernate 3.2 to generate the schema in my SQL Server database and I want the Client property of the User class to be mapped to a ClientId column with foreign key. My convention code looks like this:

mapper.AfterMapManyToOne += (inspector, member, map) =>
{
    map.Column(member.LocalMember.Name + "Id");
    // ...
};

This works, in that I get a column ClientId that is mapped as a foreign key, but I also end up with a Client column that is also mapped as a foreign key. It seems that NHibernate is treating the Client property as both a standard Property (and thus generating the Client column for it), and also a ManyToOne property (resulting in the additional ClientId column). How can I prevent the Client column from being generated

Chris
  • 27,596
  • 25
  • 124
  • 225

1 Answers1

0

I have just copied your EXACT code and, after making the properties virtual, the behavior is the expected (there's a single column, ClientId)

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154