开发者

Fluent NHibernate Mapping Error (Id column)

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"开发者_Go百科);
        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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜