NHibernate映射异常:来自表dbo.AccountGroup的关联引用了一个未映射的类:System.String

时间:2009-12-01 14:05:19

标签: fluent-nhibernate

我收到此错误:

表dbo.AccountGroup中的关联引用了未映射的类:System.String

这是我的实体:

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

这是我的映射:

    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);
        References(x => x.Group)
            .Column("AccountGroupId");
        HasMany(x => x.LedgerEntries)
            .KeyColumn("AccountId")
            .Inverse()
            .Cascade.All();
    }

以下是我的表格:

CREATE TABLE AccountGroup (     Id int PRIMARY KEY,     名称varchar(20),     父int,     描述varchar(20) )

CREATE TABLE帐户 (     Id int PRIMARY KEY,     代码varchar(30),     名称varchar(20),     描述varchar(20),     类别int,     AccountGroupId int,     FOREIGN KEY(AccountGroupId)REFERENCES AccountGroup(Id) )

1 个答案:

答案 0 :(得分:15)

你有

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

当Parent定义为

public virtual string Parent { get; set; }

你不能引用一个字符串(除非它是一个集合元素)

相关问题