NHibernate 未获取连接
我有一个在两个表中定义的实体,使用 Fluent NHibernate
Table one:
Employee
---------
Id,
Name
Table Two:
Salaries
--------
Employee_Id,
Salary
在 Fluent NHibernate 上,我将其定义如下:
EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Table("Employee");
Map(x => x.Id);
Map (x => x.Name);
Join ("Salaried", m =>
{
m.Map (x => map.Salary);
m.KeyColumn("EmployeeId");
});
}
}
当我执行 Session.Get 时,如下所示:
Employee e = session.Get<Employee>(employeeId);
然后我获得了 Employee 的所有详细信息,除了来自“Salaries”的列“表
有什么想法吗?
I have an entity that is defined in two tables with fluent nhibernate
Table one:
Employee
---------
Id,
Name
Table Two:
Salaries
--------
Employee_Id,
Salary
On Fluent NHibernate I defined it like this:
EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Table("Employee");
Map(x => x.Id);
Map (x => x.Name);
Join ("Salaried", m =>
{
m.Map (x => map.Salary);
m.KeyColumn("EmployeeId");
});
}
}
When I do a Session.Get like the following:
Employee e = session.Get<Employee>(employeeId);
Then I got all the details of Employee, except the columns coming from the "Salaries" table
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您使用 HasOne 方法,如下所示:
}
I'd suggest that you use the HasOne method like so:
}
Employee 是延迟加载的,因此 NHibernate 仅在您访问 Salary 属性时才会调用数据库。
The Employee is being lazy loaded so NHibernate will only call out to the database if you access the Salary property.
连接映射。应该是:
Join("薪水", m =>
{
m.Map(x =>map.Salary);
m.KeyColumn("Employee_Id");
});
The table and KeyColumn names are wrong in the join mapping. Should be:
Join ("Salaries", m =>
{
m.Map (x => map.Salary);
m.KeyColumn("Employee_Id");
});