【发布时间】:2015-01-19 15:02:07
【问题描述】:
我想使用 FN 在表之间进行连接。 但是我得到的输出不是很正确的结果。 我的代码:
public class Store
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual IList<Product> Products { get; protected set; }
public virtual IList<Employee> Staff { get; protected set; }
public virtual string FirstName { get; set; }
}
public StoreMap()
{
Table("store");
Id(store => store.Id).Column("id").GeneratedBy.Increment();
Map(store => store.Name).Column("name");
Join("employee", m =>
{
m.Optional();
m.KeyColumn("store_id");
m.Map(x => x.FirstName).Column("first_name");
});
}
var shops = session.QueryOver<Store>().Where(shop => shop.Id == 1).List();
生成的 SQL 查询
SELECT this_.id as id3_0_,
this_.name as name3_0_,
this_1_.first_name as first2_0_0_
FROM store this_
left outer join employee
this_1_ on this_.id=this_1_.store_id
WHERE this_.id == 1
如果我只是执行这个 SQL 查询,我会在表单中得到正确的结果
id3_0_ name3_0_ first2_0_0_
1 Bargin Basin Daisy
1 Bargin Basin Jack
1 Bargin Basin Sue
但是如果我是通过FN来做的,那么变量shops我得到如下数组:
1 Bargin Basin Daisy
1 Bargin Basin Daisy
1 Bargin Basin Daisy
我使用 FN 版本 2.0.1.0,NHibernate 4.0。谢谢。
【问题讨论】:
标签: c# nhibernate left-join fluent