Count number of Users

Asked

Viewed 45 times

0

I have a Client class, and a Systems Class.

A customer has one or more systems:

public class ClienteEmpresa : Pessoa
{

 public virtual ICollection<TipoDeSistemas> TipoDeSistemas { get; set; }
}

And the systems class has one or many Clients:

 public class TipoDeSistemas
    { 
  public virtual ICollection<ClienteEmpresa> ClienteEmpresa { get; set; }
    }

I’d like to know how I count how many users use the X system. for example: Maria, João, José, and Lurdes, use the system W. wanted to know how to do this Count(), using Entity, with labdas expressions. Someone to give me a hint?

I made a way here, that’s worked.

List<TipoDeSistemas> sis = db.TipoDeSistemaDb.ToList();

            var si = sis.Find(c => c.Descricao == "SMC");
            ViewBag.Smc = si.ClienteEmpresa.Count(c => c.StatusCliente == StatusCliente.Ativo);

            var merchant = sis.Find(c => c.Descricao == "MERCHANT");
            ViewBag.Merchantd = merchant.ClienteEmpresa.Count(c => c.StatusCliente == StatusCliente.Ativo);

            var manifestacao = sis.Find(c => c.Descricao == "MANIFESTAÇÃO");
            ViewBag.Manifestacao = manifestacao.ClienteEmpresa.Count(c => c.StatusCliente == StatusCliente.Ativo);

            var cte = sis.Find(c => c.Descricao == "CT-e");
            ViewBag.CTe = cte.ClienteEmpresa.Count(c => c.StatusCliente == StatusCliente.Ativo);
  • I suggest adding in the question the code you are using to query the database data with which you have already initialized.

  • Put the code from your repository, currently you are iterating in a list in memory, in which case you can use the method syntax (lambda) to generate an SQL and run directly in your database. Thus your application gains more performance.

No answers

Browser other questions tagged

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