0

I have a Fluent Nhibernate map like :

 public class UserMap : ClassMap<PortalUser>
{
    public UserMap()
    {
        WithTable("aspnet_Users");
        Id(x => x.Id, "UserId")
            .GeneratedBy.Guid();
        Map(x => x.Name, "UserName");
        Map(x => x.Login, "LoweredUserName");
        WithTable("LdapUsers", m => m.Map(x => x.FullName, "FullName"));

    }
}

My foreign key column in table "LdapUser" is UserId but the select that gets generated is going to look for a "PortalUserId".
Is there a way to specify the relation key direcly?

Ronnie
  • 4,959
  • 10
  • 51
  • 69

1 Answers1

2

Try this:

...
WithTable("LdapUsers", m => {
    m.Map(x => x.FullName, "FullName");
    m.WithKeyColumn("UserId");
});
Stuart Childs
  • 3,295
  • 1
  • 19
  • 11
  • I think you mean m.WithKeyColumn("UserId"); – Jamie Ide Apr 28 '09 at 17:43
  • WithTable is creating a element and, if I understand correctly, is supposed to refer the the key column on the joined table. Ronnie said his foreign key is "LdapUser" so the query should look something like ... FROM aspnet_Users a INNER JOIN LdapUsers b ON a.UserId = b.LdapUser. My reference: http://ayende.com/Blog/archive/2007/04/24/Multi-Table-Entities-in-NHibernate.aspx But you could be right, Jamie; I honestly have no idea... I've never had to use this construct. :) – Stuart Childs Apr 28 '09 at 18:13
  • Actually my foreign column was "UserId" in table "LdapUser" and putting it instead of "LdapUser" worked perfectly. Thanks again. – Ronnie Apr 29 '09 at 08:10
  • Glad it worked... and sorry Jamie, you were dead on but I wasn't paying enough attention apparently. I updated my post in case someone stumbles upon this later. – Stuart Childs Apr 29 '09 at 12:48
  • Hey Stuart this is ok for setting the key of the linked table but it automatically joins with the primary key of the base table. How to setup a join with a different column that is not the pk? – Ronnie Apr 29 '09 at 17:10
  • I'm not sure that this is possible to be honest. You might want to create a new question for that and link back to this one for full context. You're likely to get more exposure for your new question that way... maybe someone else knows a way to do it. – Stuart Childs Apr 29 '09 at 19:04