walterDFF 0 Denunciar post Postado Junho 5, 2014 Alguém sabe fazer um full outer join com linq? Já vi diversos tutoriais na internet e não encontro uma maneira de fazer esse relacionamento, alguém poderia me ajudar? \\ DataTable tb2; \\ DataTable tb; var moedaPadrao = tb2.AsEnumerable(); var moedaSelecionada = tb.AsEnumerable(); var novoDt = from a in moedaPadrao join c in moedaSelecionada on a.Field<string>("COD_CONTA") equals c.Field<string>("COD_CONTA") select new { COD_CONTA = a.Field<string>("COD_CONTA"), DESCRICAO = a.Field<string>("DESCRICAO") == null ? "-" : a.Field<string>("DESCRICAO") }; Compartilhar este post Link para o post Compartilhar em outros sites
walterDFF 0 Denunciar post Postado Junho 6, 2014 Como eu sou um bom moço vou postar a solução.. depois de apanhar bastante! var moedaPadrao = tb2.AsEnumerable(); var moedaSelecionada = tb.AsEnumerable(); string codDetalhe1 = "codDetalhe1", codDetalhe2 = "codDetalhe2", codDetalhe3 = "codDetalhe3", codDetalhe4 = "codDetalhe4", codDetalhe5 = "codDetalhe5"; Decimal saldo_ini_moeda = 0, debito_moeda = 0, credito_moeda = 0, saldo_fim_moeda = 0; var novoDtLeft = from a in moedaPadrao.DefaultIfEmpty() join c in moedaSelecionada.DefaultIfEmpty() on new { COD_CONTA = a == null ? "" : a.Field<string>("COD_CONTA"), codDetalhe1 = detalhamento1 == null ? 0 : a.Field<int>("codDetalhe1"), codDetalhe2 = detalhamento2 == null ? 0 : a.Field<int>("codDetalhe2"), codDetalhe3 = detalhamento3 == null ? 0 : a.Field<int>("codDetalhe3"), codDetalhe4 = detalhamento4 == null ? 0 : a.Field<int>("codDetalhe4"), codDetalhe5 = detalhamento5 == null ? 0 : a.Field<int>("codDetalhe5") } equals new { COD_CONTA = c == null ? "" : c.Field<string>("COD_CONTA"), codDetalhe1 = detalhamento1 == null ? 0 : c.Field<int>("codDetalhe1"), codDetalhe2 = detalhamento2 == null ? 0 : c.Field<int>("codDetalhe2"), codDetalhe3 = detalhamento3 == null ? 0 : c.Field<int>("codDetalhe3"), codDetalhe4 = detalhamento4 == null ? 0 : c.Field<int>("codDetalhe4"), codDetalhe5 = detalhamento5 == null ? 0 : c.Field<int>("codDetalhe5") } into dtTemp from c in dtTemp.DefaultIfEmpty() select new { COD_CONTA = a == null ? c.Field<string>("COD_CONTA") : a.Field<string>("COD_CONTA"), DESCRICAO = a == null ? c.Field<string>("DESCRICAO") : a.Field<string>("DESCRICAO"), saldo_ini = a == null ? 0 : a.Field<Decimal>("saldo_ini"), debito = a == null ? 0 : a.Field<Decimal>("debito"), credito = a == null ? 0 : a.Field<Decimal>("credito"), saldo_fim = a == null ? 0 : a.Field<Decimal>("saldo_fim"), saldo_ini_moeda = c != null ? c.Field<Decimal>("saldo_ini") : 0, debito_moeda = c != null ? c.Field<Decimal>("debito") : 0, credito_moeda = c != null ? c.Field<Decimal>("credito") : 0, saldo_fim_moeda = c != null ? (c.Field<Decimal>("saldo_ini") + c.Field<Decimal>("debito") - c.Field<Decimal>("credito")) : 0, codDetalhe1 = detalhamento1 == null ? 0 : a == null ? c.Field<int>("codDetalhe1") : a.Field<int>("codDetalhe1"), codDetalhe2 = detalhamento2 == null ? 0 : a == null ? c.Field<int>("codDetalhe2") : a.Field<int>("codDetalhe2"), codDetalhe3 = detalhamento3 == null ? 0 : a == null ? c.Field<int>("codDetalhe3") : a.Field<int>("codDetalhe3"), codDetalhe4 = detalhamento4 == null ? 0 : a == null ? c.Field<int>("codDetalhe4") : a.Field<int>("codDetalhe4"), codDetalhe5 = detalhamento5 == null ? 0 : a == null ? c.Field<int>("codDetalhe5") : a.Field<int>("codDetalhe5"), descDetalhe1 = detalhamento1 == null ? "" : a == null ? c.Field<string>("descDetalhe1") : a.Field<string>("descDetalhe1"), descDetalhe2 = detalhamento2 == null ? "" : a == null ? c.Field<string>("descDetalhe2") : a.Field<string>("descDetalhe2"), descDetalhe3 = detalhamento3 == null ? "" : a == null ? c.Field<string>("descDetalhe3") : a.Field<string>("descDetalhe3"), descDetalhe4 = detalhamento4 == null ? "" : a == null ? c.Field<string>("descDetalhe4") : a.Field<string>("descDetalhe4"), descDetalhe5 = detalhamento5 == null ? "" : a == null ? c.Field<string>("descDetalhe5") : a.Field<string>("descDetalhe5"), analitica = a.Field<int>("analitica") }; var novoDtRight = from a in moedaSelecionada.DefaultIfEmpty() join c in moedaPadrao.DefaultIfEmpty() on new { COD_CONTA = a == null ? "" : a.Field<string>("COD_CONTA"), codDetalhe1 = detalhamento1 == null ? 0 : a.Field<int>("codDetalhe1"), codDetalhe2 = detalhamento2 == null ? 0 : a.Field<int>("codDetalhe2"), codDetalhe3 = detalhamento3 == null ? 0 : a.Field<int>("codDetalhe3"), codDetalhe4 = detalhamento4 == null ? 0 : a.Field<int>("codDetalhe4"), codDetalhe5 = detalhamento5 == null ? 0 : a.Field<int>("codDetalhe5") } equals new { COD_CONTA = c == null ? "" : c.Field<string>("COD_CONTA"), codDetalhe1 = detalhamento1 == null ? 0 : c.Field<int>("codDetalhe1"), codDetalhe2 = detalhamento2 == null ? 0 : c.Field<int>("codDetalhe2"), codDetalhe3 = detalhamento3 == null ? 0 : c.Field<int>("codDetalhe3"), codDetalhe4 = detalhamento4 == null ? 0 : c.Field<int>("codDetalhe4"), codDetalhe5 = detalhamento5 == null ? 0 : c.Field<int>("codDetalhe5") } into dtTemp from c in dtTemp.DefaultIfEmpty() select new { COD_CONTA = a == null ? c.Field<string>("COD_CONTA") : a.Field<string>("COD_CONTA"), DESCRICAO = a == null ? c.Field<string>("DESCRICAO") : a.Field<string>("DESCRICAO"), saldo_ini = c == null ? 0 : c.Field<Decimal>("saldo_ini"), debito = c == null ? 0 : c.Field<Decimal>("debito"), credito = c == null ? 0 : c.Field<Decimal>("credito"), saldo_fim = c == null ? 0 : c.Field<Decimal>("saldo_fim"), saldo_ini_moeda = a != null ? a.Field<Decimal>("saldo_ini") : 0, debito_moeda = a != null ? a.Field<Decimal>("debito") : 0, credito_moeda = a != null ? a.Field<Decimal>("credito") : 0, saldo_fim_moeda = a != null ? (a.Field<Decimal>("saldo_ini") + a.Field<Decimal>("debito") - a.Field<Decimal>("credito")) : 0, codDetalhe1 = detalhamento1 == null ? 0 : a == null ? c.Field<int>("codDetalhe1") : a.Field<int>("codDetalhe1"), codDetalhe2 = detalhamento2 == null ? 0 : a == null ? c.Field<int>("codDetalhe2") : a.Field<int>("codDetalhe2"), codDetalhe3 = detalhamento3 == null ? 0 : a == null ? c.Field<int>("codDetalhe3") : a.Field<int>("codDetalhe3"), codDetalhe4 = detalhamento4 == null ? 0 : a == null ? c.Field<int>("codDetalhe4") : a.Field<int>("codDetalhe4"), codDetalhe5 = detalhamento5 == null ? 0 : a == null ? c.Field<int>("codDetalhe5") : a.Field<int>("codDetalhe5"), descDetalhe1 = detalhamento1 == null ? "" : a == null ? c.Field<string>("descDetalhe1") : a.Field<string>("descDetalhe1"), descDetalhe2 = detalhamento2 == null ? "" : a == null ? c.Field<string>("descDetalhe2") : a.Field<string>("descDetalhe2"), descDetalhe3 = detalhamento3 == null ? "" : a == null ? c.Field<string>("descDetalhe3") : a.Field<string>("descDetalhe3"), descDetalhe4 = detalhamento4 == null ? "" : a == null ? c.Field<string>("descDetalhe4") : a.Field<string>("descDetalhe4"), descDetalhe5 = detalhamento5 == null ? "" : a == null ? c.Field<string>("descDetalhe5") : a.Field<string>("descDetalhe5"), analitica = a.Field<int>("analitica") }; tb = novoDtLeft.Union(novoDtRight).OrderBy(r => r.COD_CONTA).CopyToDataTable(); Compartilhar este post Link para o post Compartilhar em outros sites