Free NHibernate mapping error (identity column)

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

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 indicated that the "AccountId" column.

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);
    }
}

      

Did I miss something?

+2


source to share


1 answer


My bad one. I was missing the 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.

+5


source







All Articles