开发者

QueryOver - JoinQueryOver problems

i How to use queryover (Join) for same table...example

    if (!string.IsNullOrEmpty(ufResidencia) || 
        !string.IsNullOrEmpty(cidadeResidencia))
    {
        EnderecoProspect endPros = null;
        TipoEndereco tipoEnd = 开发者_StackOverflownull;
        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");

    }

When I try to run I get the message that the path is duplicated. Im using alias correct? what problem? havy ideal? exception is "duplicate association path"


I managed to solve with LINQ to NHibernate ... there is the example for all ...

  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"
                  )

Now I can sleep a little more until ...ehehehe...see you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜