views:

160

answers:

1

Okay so I have two tables:

Companies
    | id int
    | name varchar(50)

and

Contacts
    | id int
    | name varchar(50)
    | companyID int

In my code I have the following classes

public class Company
{
    public int Identity { get; set; }
    public string Name { get; set; }
    public IList<Contact> Contacts { get; set; }
}

and

public class Contact
{
    public int Identity { get; set; }
    public string Name { get; set; }
    public Company Company { get; set; }
}

And my fluent nhibernate mappings as so:

public class CompanyMapping : ClassMap<Company>
{
    public CompanyMapping()
    {
        WithTable("Companies");

        Id(x => x.Identity, "Id");
        Map(x => x.Name);            
        HasMany<Contact>(x => x.Contacts)                                                
            .Inverse()                
            .LazyLoad()                
            .Cascade.All()
            .AsList();                
    }
}

and

public class ContactMapping : ClassMap<Contact>
{
    public ContactMapping()
    {
        WithTable("Contacts");

        Id(x => x.Identity, "Id");
        References<Company>(x => x.Company, "CompanyID");
        Map(x => x.Name);
    }
}

Yet when I try to access the Company.Contacts property I get the following error

Invalid column name 'Company_id'.
Invalid column name 'Company_id'.

(yes twice in one message)

obviously the key column on the contacts table isn't called Company_id it's called CompanyID

So what am I doing wrong? I can't seem to set what the Key Column as WithKeyColumn doesn't seem to exist (it's what I've found in other solutions people have done, but they might be using a different version of fluent nhibernate to me)

Thanks in advance

A: 

http://stackoverflow.com/questions/657056/fluent-nhibernate-hasmany-withkeycolumnname

solved it :)

Edit:

Apparently, because I've accepted my own answer on another question today, I have to wait another two days to do so.

That kind sucks but meh.

Sekhat