ERROR System.Invalidoperationexception: The sequence contains more than one element

Asked

Viewed 1,419 times

1

I have a system that works in several machines, but in one machine the error occurs:

`The sequence contains more than one element Description: An untreated exception occurred during the execution of the current web request. Examine stack tracking for more information about the error and where it originated in the code.

Exception Details: System.Invalidoperationexception: The sequence contains more than one element

Error of Origin:

Untreated exception was generated during the execution of the current web request. Information related to the origin and location of the exception can be identified using the exception stack tracking below.

Cell Trace:

[Invalidoperationexception: The sequence contains more than one element] System.Linq.Enumerable.Singleordefault(Ienumerable1 source) +4098162 System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2(IEnumerable1 Quence) +40 System.Data.Entity.Core.Objects.ELinq.Objectqueryprovider.Executesingle(Ienumerable`1 query, Expression queryRoot) +60 System.Data.Entity.Core.Objects.ELinq.Objectqueryprovider.System.Linq.Iqueryprovider

The system accesses the following action

string Login = Getuser();

        Ramal ramal = db.Ramais.SingleOrDefault(r => r.sCodFunc == Login);

        if (ramal == null)
        {
            Session["UserAdm"] = false;
        }
        else
        {
            Session["UserAdm"] = ramal.bAdmSist;
        }

        ViewBag.ListaMes = MontaListaMes();
        ViewBag.Area = (from c in db.Area orderby c.sNome select c).ToArray();

        //return View();

        //Exibir os aniversariantes do mês

        string MesAniversario = DateTime.Today.ToString("MM");
        string DiaAniversario = DateTime.Today.ToString("dd");


        //Coloca em primeiro o aniversariante do dia, e em seguida do mes.
        Ramal[] RamalAniver = (from c in db.Ramais
                               where c.sAniversario.Contains("/" + MesAniversario) && c.bAtivo == true
                               orderby c.sAniversario
                               select c
                               ).ToArray();


        RamalAniver = RamalAniver.OrderByDescending(x => x.sAniversario == DiaAniversario 
            + "/" + MesAniversario).ThenBy(x => x.sAniversario).ToArray();


        return View(RamalAniver.ToList());

        //return View(AniverDia.Union(AniverMes).ToList());

    private string GetUser()
    {

        var Aux = User.Identity.Name.Split('\\');
        return Aux[1];
    }

Has anyone ever seen this problem?

  • 1

    Updating, The error was occurring because in my query, I was returning more than one record on Ramal ramal = db.Ramais.SingleOrDefault(r => r.sCodFunc == Login); Att

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.