开发者

NHibernate Mapping Exception: An association from the table dbo.AccountGroup refers to an unmapped class: System.String

I am getting this error:

An association from the table dbo.AccountGroup refers to an unmapped class: System.String

This is my entity:

public class AccountGroup
{
    public virtual int Id { get; private set; }
    public virtual string Name { get; set; }
    public virtual string Parent { get; set; }
    public virtual string Description { get; set; }
    public virtual IList<Account> Accounts { get; set; }

    public AccountGroup()
    {
        this.Accounts = new List<Account>();
    }
}

public class Account
{
    public virtual int Id { get; private set; }
    public virtual string Code { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }
    public virtual int Category { get; set; }
    public virtual AccountGroup Group { get; set; }
    public virtual IList<LedgerEntry> LedgerEntries { get; set; }

    public Account()
    {
        this.LedgerEntries = new List<LedgerEntry>();
    }
}

This is my mapping:

    public AccountGroupMap()
    {
        Table("dbo.AccountGroup");
        Id(x => x.Id)
            .Column("Id");
        Map(x => x.Name);
        References(x => x.Parent)
            .Column("Parent");
        Map(x => x.Description);
        HasMany(x => x.Accounts)
            .KeyColumn("GroupId")
            .Inverse()
            .Cascade.All();
    }
}

    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);
        Reference开发者_运维知识库s(x => x.Group)
            .Column("AccountGroupId");
        HasMany(x => x.LedgerEntries)
            .KeyColumn("AccountId")
            .Inverse()
            .Cascade.All();
    }

Here are my tables:

CREATE TABLE AccountGroup ( Id int PRIMARY KEY, Name varchar(20), Parent int, Description varchar(20) )

CREATE TABLE Account ( Id int PRIMARY KEY, Code varchar(30), Name varchar(20), Description varchar(20), Category int, AccountGroupId int, FOREIGN KEY (AccountGroupId) REFERENCES AccountGroup (Id) )


You have

References(x => x.Parent)
        .Column("Parent");

When Parent is defined as

public virtual string Parent { get; set; }

You can't reference a string (unless it's a collection element)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜