Fluent NHibernate在映射构造函数中添加Where()不适用于子查询



我有这个实体映射:

public class ExpedienteNnaMap : ClassMap<ExpedienteNna>
{
public ExpedienteNnaMap()
{
Table("personasexpediente");
Id(x => x.Id, "gidexpediente");
Map(x => x.FechaCreacion, "fecha");
References(x => x.DetalleNna, "gidpersona").Not.LazyLoad();
HasOne(x => x.CondicionMedica).ForeignKey("numero_expediente").Not.LazyLoad();
Where("expnna = 'nna' AND gidexpediente in (select numero_instrumento from seguimiento s where idcustodio = '23')");
}
}

当我尝试运行我的get所有查询Fluent NHibernate生成以下SQL语句:

select
expediente0_.gidexpediente as gidexpediente1_9_,
expediente0_.fecha as fecha2_9_,
expediente0_.gidpersona as gidpersona3_9_
from
personasexpediente expediente0_
where
( 
expediente0_.expnna = 'nna'
and expediente0_.gidexpediente in 
(
select
expediente0_.numero_instrumento
from
seguimiento s
where
expediente0_.idcustodio = '23'
)
)

我只需要NHibernate避免在子查询

中使用别名

设置子查询的别名。当没有设置别名时,NHibernate将假定它是映射表的一列,并分配它的别名

Where("expnna = 'nna' AND gidexpediente in (select s.numero_instrumento from seguimiento s where s.idcustodio = '23')");

最新更新