QueryOver - JoinQueryOver问题

时间:2011-04-22 00:13:02

标签: nhibernate fluent-nhibernate queryover

i如何对同一个表使用查询(加入)...示例

    if (!string.IsNullOrEmpty(ufResidencia) || 
        !string.IsNullOrEmpty(cidadeResidencia))
    {
        EnderecoProspect endPros = null;
        TipoEndereco tipoEnd = null;
        query
            .JoinQueryOver<EnderecoProspect>(x => x.Enderecos,()=> endPros)
                .And(()=> endPros.Uf ==ufResidencia)
                    .JoinQueryOver<TipoEndereco>(x => x.TipoEndereco,()=> tipoEnd)
                        .And(()=> tipoEnd.Descricao != "Fazenda");
    }

    if (!string.IsNullOrEmpty(ufFazenda) ||
        !string.IsNullOrEmpty(cidadeFazenda))
    {
        EnderecoProspect endPros1 = null;
        TipoEndereco tipoEnd1 = null;
        query
            .JoinQueryOver<EnderecoProspect>(x => x.Enderecos,()=> endPros1)
                .And(()=> endPros1.Uf ==ufFazenda)
                    .JoinQueryOver<TipoEndereco>(x => x.TipoEndereco,()=> tipoEnd1)
                        .And(()=> tipoEnd1.Descricao == "Fazenda");

    }

当我尝试运行时,我收到路径重复的消息。我使用别名正确吗?什么问题? havy理想吗?异常是“重复关联路径”

1 个答案:

答案 0 :(得分:2)

我设法用LINQ来解决NHibernate ...有所有的例子......

  var q =
            from c in Context.Query<Prospect>()
            join o in Context.Query<EnderecoProspect>() on c.Identificacao equals                   o.Prospect.Identificacao
            join e in Context.Query<TipoEndereco>() on o.TipoEndereco.Identificacao equals e.Identificacao
            join a in Context.Query<EnderecoProspect>() on c.Identificacao equals a.Prospect.Identificacao
            join b in Context.Query<TipoEndereco>() on a.TipoEndereco.Identificacao equals b.Identificacao
            where (
                    (
                        (o.Uf == ufFazenda || ufFazenda == null) &&
                        (o.Cidade == cidadeFazenda || cidadeFazenda == null)
                    ) && e.Descricao == "Fazenda"
                  )
                  &&
                  (
                    (
                        (a.Uf == ufResidencia || ufResidencia == null) &&
                        (a.Cidade == cidadeResidencia || cidadeResidencia == null)
                    ) && b.Descricao != "Fazenda"
                  )

现在我可以多睡一会儿直到......嘿嘿......见到你

相关问题