早上好,伙计们。
我遇到了NHibernate生成的查询问题。我的映射就像下面一样:
public class Matricula
{
[BelongsTo("IdTurma", NotNull=True)]
public Turma {get;set;}
}
public class Turma
{
[BelongsTo("IdCurso", NotNull=True)]
public Curso {get;set;}
}
public class Curso
{
[PrimaryKey("IdCurso", Generator=PrimaryKeyType.Identity)]
public int IdCurso{get;set;}
}
问题是:Nh生成查询,左边应该是内部。在Matricula和Turma之间它们是内在的,但是在Turma和Curso之间它们使得在外面。什么问题?怎么了?
我的查询:
SELECT this_.IdMatricula as IdMatric1_122_14_,
this_.IdTurma as IdTurma122_14_,
this_.IdUsuario as IdUsuario122_14_,
turma3_.IdTurma as IdTurma25_0_,
turma3_.idTurmaStatus as idTurmaS2_25_0_,
turma3_.IdCurso as IdCurso25_0_,
curso4_.IdCurso as IdCurso31_1_,
curso4_.idStatus as idStatus31_1_,
curso4_.IdTipoCurso as IdTipoC10_31_1_,
curso4_.IdOrganization as IdOrgan11_31_1_,
statuscurs5_.idStatus as idStatus54_2_,
statuscurs5_.strStatus as strStatus54_2_,
tipocurso6_.strDescricao as strDescr2_125_3_,
padraocomu7_.strNmPadrao as strNmPad2_103_4_,
organizati8_.Id_Organization as Id1_87_5_,
organizati8_.strTitle as strTitle87_5_,
cursoprese9_.IdCurso as IdCurso6_6_,
turmastatu10_.idTurmaStatus as idTurmaS1_91_7_,
usuario1_.IdUsuario as IdUsuario116_10_,
organizaca14_.idOrganizacao as idOrgani1_83_11_,
cargo15_.idCargo as idCargo7_12_,
matriculas16_.idMatriculaStatus as idMatric1_15_13_
FROM tracking.matriculas this_
inner join cursos.turmas turma3_ on this_.IdTurma=turma3_.IdTurma
left outer join schemadbo.cursos curso4_ on turma3_.IdCurso=curso4_.IdCurso
left outer join schemadbo.status statuscurs5_ on curso4_.idStatus=statuscurs5_.idStatus
left outer join schemadbo.tipos tipocurso6_ on curso4_.IdTipoCurso=tipocurso6_.IdTipoCurso
left outer join schemadbo.PadraoComunicacao padraocomu7_ on curso4_.IdPadraoComunicacao=padraocomu7_.IdPadrao
left outer join schemadbo.lms_cp_organizations organizati8_ on curso4_.IdOrganization=organizati8_.Id_Organization
left outer join schemadbo.CursosPresenciais cursoprese9_ on curso4_.IdCurso=cursoprese9_.IdCurso
left outer join schemadbo.turmasstatus turmastatu10_ on turma3_.idTurmaStatus=turmastatu10_.idTurmaStatus
left outer join schemadbo.turmaspresenciais turmaprese11_ on turma3_.IdTurma=turmaprese11_.idTurma
inner join schemadbo.matriculasresumo matricular12_ on this_.IdMatricula=matricular12_.IdMatricula
inner join schemadbo.usuarios usuario1_ on this_.IdUsuario=usuario1_.IdUsuario
left outer join schemadbo.Organizacoes organizaca14_ on usuario1_.idOrganizacao=organizaca14_.idOrganizacao
left outer join schemadbo.cargos cargo15_ on usuario1_.idCargo=cargo15_.idCargo
inner join schemadbo.matriculasstatus matriculas16_ on this_.idMatriculaStatus=matriculas16_.idMatriculaStatus
WHERE this_.IdTurma = @p0
答案 0 :(得分:2)
我们在最后遇到了类似的问题。为了提高性能,我们将FetchEnum.Join添加到了BelongsTo属性,这对我们起了作用。
[BelongsTo("IdCurso", NotNull = true, Fetch=FetchEnum.Join)]