Question

I'm getting a mapping error in Fluent NHibernate. Why is it still looking for _id when I have specified the column explicitly?

Invalid column name 'Account_id'.
[GenericADOException: could not initialize a collection: [ProtoStack.Business.Entities.Account.LedgerEntries#1][SQL: SELECT ***ledgerentr0_.Account_id*** as Account5_1_, ledgerentr0_.Id as Id1_, ledgerentr0_.Id as Id43_0_, ledgerentr0_.LedgerEntryDate as LedgerEn2_43_0_, ledgerentr0_.Amount as Amount43_0_, ledgerentr0_.AccountId as AccountId43_0_ FROM dbo.LedgerEntry ledgerentr0_ WHERE ledgerentr0_.Account_id=?]]

I have explicitly specified that the column is "AccountId".

public class AccountMap : ClassMap<Account>
{
    public AccountMap()
    {
        Table("dbo.Account");
        Id(x => x.Id)
            .Column("Id");
        Map(x => x.Code);
        Map(x => x.Name);
        Map(x => x.Description);
        Map(x => x.Category);
        References(x => x.Group)
            .Column("AccountGroupId");
        HasMany(x => x.LedgerEntries)
            .Inverse()
            .Cascade.All();
    }
}

public class LedgerEntryMap : ClassMap<LedgerEntry>
{
    public LedgerEntryMap()
    {
        Table("dbo.LedgerEntry");
        Id(x => x.Id)
            .Column("Id");
        References(x => x.Account)
            .Column("AccountId");
        Map(x => x.LedgerEntryDate);
        Map(x => x.Amount);
    }
}

Am I missing something?

Was it helpful?

Solution

My bad. I was missing KeyColumn.

    public class AccountMap : ClassMap<Account>
{
    public AccountMap()
    {
        Table("dbo.Account");
        Id(x => x.Id)
            .Column("Id");
        Map(x => x.Code);
        Map(x => x.Name);
        Map(x => x.Description);
        Map(x => x.Category);
        References(x => x.Group)
            .Column("AccountGroupId");
        HasMany(x => x.LedgerEntries)
            .KeyColumn("AccountId")
            .Inverse()
            .Cascade.All();
    }
}

Works now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top