子表连接表中的子句

时间:2013-09-05 08:14:51

标签: c# nhibernate nhibernate-mapping mapping-by-code

我必须单个表存储所有数据。我将Employee实体映射到Department属性,如下所示:

ManyToOne(x => x.Department, m =>
        {
            m.Unique(true);
            m.Column("LookupColumn3");
            m.Fetch(FetchKind.Join);
            m.Access(Accessor.Property);
            m.Lazy(LazyRelation.NoLazy);

            Where("ListId='DepartmentGuid' or ListId null");
        });
Where("ListId='EmployeeListId'");

但是在生成的SQL中,相同的this_别名用于父和子Where子句

修改

现在这变得非常实际,因为我测量了生成的SELECT(表格有150'000行):

SELECT TOP (10)  this_.ID  /* other fields */
FROM AllData this_ left outer join AllData lookups on this_.lookupColumn1=lookups.ID    
WHERE this_.EntityType = @p1 and this_.Id = @p2 and lookups.EntityType = @p26 /* other criteria */
ORDER BY this_.ID desc
/* Executed in 23seconds! */

SELECT TOP (10)  this_.ID  /* other fields */
FROM AllData this_ left outer join AllData lookups on this_.lookupColumn1=lookups.ID 
and lookups.EntityType = @p26 /* other criteria */
WHERE this_.EntityType = @p1 and this_.Id = @p2
ORDER BY this_.ID desc
/* Executed in less then 0.1 miliseconds */

0 个答案:

没有答案