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

发布于 2024-08-13 10:09:15 字数 2131 浏览 1 评论 0原文

我收到此错误:

表 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 主键, 名称 varchar(20), 父整数, 说明 varchar(20) )

创建表帐户 ( Id int 主键, 代码 varchar(30), 名称 varchar(20), 描述 varchar(20), 类别 int, AccountGroupId int, 外键 (AccountGroupId) 参考 AccountGroup (Id) )

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝色星空 2024-08-20 10:09:15

当Parent

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

被定义为

public virtual string Parent { get; set; }

您不能引用字符串时(除非它是集合元素)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文