NHibernate 映射异常:表 dbo.AccountGroup 中的关联引用未映射的类:System.String
我收到此错误:
表 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当Parent
被定义为
您不能引用字符串时(除非它是集合元素)
You have
When Parent is defined as
You can't reference a string (unless it's a collection element)