Erro tipo numa List
21/10/2014
0
Depois de muita pesquisa, consegui terminar meu código em LINQ. Se eu coloco esse código direto num button e faço um .ToList() no final, ele funciona perfeitamente. Mas se eu coloco num método, aparece o seguinte erro:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<PesquisaView.view_ok>'
Já tentei colocar depois do a classe automaticamente gerada pelo Entity Framework: . Mas e preciso gerar um campo a mais que não existe na tabela criada (campo 'resultado' no código abaixo).
No final do código, dá o erro na variável query citado no começo da postagem.
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<PesquisaView.view_ok>'
Já tentei colocar depois do
select new
select new view_ok {...}
No final do código, dá o erro na variável query citado no começo da postagem.
public List<view_ok> GetPesquisar(string r8, string r9, string r10, string r11, string sexo, string prof) { string rs8 = r8; string rs9 = r9; string rs10 = r10; string rs11 = r11; string sex = sexo; string pr = prof; PesquisaBETAEntities pb = new PesquisaBETAEntities(); var query = (from t0 in ( (from v0 in pb.view_ok group v0 by new { v0.prof_nome, v0.resu1 } into g select new { g.Key.prof_nome, g.Key.resu1})) join t1 in ( from v1 in pb.view_ok where SqlFunctions.StringConvert((decimal)v1.resu8).Contains("") && SqlFunctions.StringConvert((decimal)v1.resu9).Contains("") && SqlFunctions.StringConvert((decimal)v1.resu10).Contains("") && SqlFunctions.StringConvert((decimal)v1.resu11).Contains("") && SqlFunctions.StringConvert((decimal)v1.sexo).Contains("") group v1 by new { v1.prof_nome, v1.resu1 } into g select new { g.Key.prof_nome, g.Key.resu1, perguntas = g.Count(p => p.resu1 != null) }) on new { t0.prof_nome, Resu1 = t0.resu1 } equals new { t1.prof_nome, Resu1 = t1.resu1 } into t1_join from t1 in t1_join.DefaultIfEmpty() join t2 in ( (from v2 in pb.view_ok where SqlFunctions.StringConvert((decimal)v2.resu8).Contains("") && SqlFunctions.StringConvert((decimal)v2.resu9).Contains("") && SqlFunctions.StringConvert((decimal)v2.resu10).Contains("") && SqlFunctions.StringConvert((decimal)v2.resu11).Contains("") && SqlFunctions.StringConvert((decimal)v2.sexo).Contains("") group v2 by new { v2.prof_nome, v2.resu2 } into g select new { g.Key.prof_nome, g.Key.resu2, perguntas = g.Count(p => p.resu2 != null) })) on new { t0.prof_nome, Resu1 = t0.resu1 } equals new { t2.prof_nome, Resu1 = t2.resu2 } into t2_join from t2 in t2_join.DefaultIfEmpty() join t3 in ( (from v3 in pb.view_ok where SqlFunctions.StringConvert((decimal)v3.resu8).Contains("") && SqlFunctions.StringConvert((decimal)v3.resu9).Contains("") && SqlFunctions.StringConvert((decimal)v3.resu10).Contains("") && SqlFunctions.StringConvert((decimal)v3.resu11).Contains("") && SqlFunctions.StringConvert((decimal)v3.sexo).Contains("") group v3 by new { v3.prof_nome, v3.resu3 } into g select new { g.Key.prof_nome, g.Key.resu3, perguntas = g.Count(p => p.resu3 != null) })) on new { t0.prof_nome, Resu1 = t0.resu1 } equals new { t3.prof_nome, Resu1 = t3.resu3 } into t3_join from t3 in t3_join.DefaultIfEmpty() join t4 in ( (from v4 in pb.view_ok where SqlFunctions.StringConvert((decimal)v4.resu8).Contains("") && SqlFunctions.StringConvert((decimal)v4.resu9).Contains("") && SqlFunctions.StringConvert((decimal)v4.resu10).Contains("") && SqlFunctions.StringConvert((decimal)v4.resu11).Contains("") && SqlFunctions.StringConvert((decimal)v4.sexo).Contains("") group v4 by new { v4.prof_nome, v4.resu4 } into g select new { g.Key.prof_nome, g.Key.resu4, perguntas = g.Count(p => p.resu4 != null) })) on new { t0.prof_nome, Resu1 = t0.resu1 } equals new { t4.prof_nome, Resu1 = t4.resu4 } into t4_join from t4 in t4_join.DefaultIfEmpty() join t5 in ( (from v5 in pb.view_ok where SqlFunctions.StringConvert((decimal)v5.resu8).Contains("") && SqlFunctions.StringConvert((decimal)v5.resu9).Contains("") && SqlFunctions.StringConvert((decimal)v5.resu10).Contains("") && SqlFunctions.StringConvert((decimal)v5.resu11).Contains("") && SqlFunctions.StringConvert((decimal)v5.sexo).Contains("") group v5 by new { v5.prof_nome, v5.resu5 } into g select new { g.Key.prof_nome, g.Key.resu5, perguntas = g.Count(p => p.resu5 != null) })) on new { t0.prof_nome, Resu1 = t0.resu1 } equals new { t5.prof_nome, Resu1 = t5.resu5 } into t5_join from t5 in t5_join.DefaultIfEmpty() join t6 in ( (from v6 in pb.view_ok where SqlFunctions.StringConvert((decimal)v6.resu8).Contains("") && SqlFunctions.StringConvert((decimal)v6.resu9).Contains("") && SqlFunctions.StringConvert((decimal)v6.resu10).Contains("") && SqlFunctions.StringConvert((decimal)v6.resu11).Contains("") && SqlFunctions.StringConvert((decimal)v6.sexo).Contains("") group v6 by new { v6.prof_nome, v6.resu6 } into g select new { g.Key.prof_nome, g.Key.resu6, perguntas = g.Count(p => p.resu6 != null) })) on new { t0.prof_nome, Resu1 = t0.resu1 } equals new { t6.prof_nome, Resu1 = t6.resu6 } into t6_join from t6 in t6_join.DefaultIfEmpty() join t7 in ( (from v7 in pb.view_ok where SqlFunctions.StringConvert((decimal)v7.resu8).Contains("") && SqlFunctions.StringConvert((decimal)v7.resu9).Contains("") && SqlFunctions.StringConvert((decimal)v7.resu10).Contains("") && SqlFunctions.StringConvert((decimal)v7.resu11).Contains("") && SqlFunctions.StringConvert((decimal)v7.sexo).Contains("") group v7 by new { v7.prof_nome, v7.resu7 } into g select new { g.Key.prof_nome, g.Key.resu7, perguntas = g.Count(p => p.resu7 != null) })) on new { t0.prof_nome, Resu1 = t0.resu1 } equals new { t7.prof_nome, Resu1 = t7.resu7 } into t7_join from t7 in t7_join.DefaultIfEmpty() where t0.prof_nome.Contains(pr) orderby t0.resu1 select new { Professor = t0.prof_nome, resultado = t0.resu1 == 60 ? "Regular" : t0.resu1 == 80 ? "Bom" : t0.resu1 == 90 ? "Ótimo" : t0.resu1 == 100 ? "Excelente" : null, p1 = (int?)t1.perguntas, p2 = (int?)t2.perguntas, p3 = (int?)t3.perguntas, p4 = (int?)t4.perguntas, p5 = (int?)t5.perguntas, p6 = (int?)t6.perguntas, p7 = (int?)t7.perguntas }).ToList(); return query; } }
Elber Domingos
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)