QueryOver - проблемы JoinQueryOver - PullRequest
       2

QueryOver - проблемы JoinQueryOver

3 голосов
/ 22 апреля 2011

i Как использовать queryover (Join) для той же таблицы ... пример

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

    }

Когда я пытаюсь запустить, я получаю сообщение, что путь дублирован. Я использую псевдоним правильно? какая проблема? хави идеал? Исключение составляет «дублированный путь ассоциации»

1 Ответ

2 голосов
/ 23 апреля 2011

Мне удалось решить с 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"
                  )

Теперь я могу поспать еще немного, пока ... эхе-хе ... увидимся1004 *

...