Compare shorter term between asp.net columns

0

Doing order system, I have several warehouses, let's suppose I have to compare 2 warehouses that have shorter lead times by using entityframework, how would I do that? I'm trying to do more but it only returns the last query value, but not the least. in the code below, I have a foreach that runs through 2 warehouses and in the end it would only return me with the shorter delivery time

                foreach (var item2 in lstDeposito)
            {

                Armazem arm = db.Armazem.Find(item2.Deposito.ArmazemId);

                var de = db.Armazem.Where(x => x.Id == arm.Id).Min(x => x.Prazo);

                int menorprazo = Convert.ToInt32(de);
            }

Store

public class Armazem
{
        public int Id { get; set; }

        [Required]
        [StringLength(50)]
        public string Nome { get; set; }

        public int Prazo { get; set; }

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

}
    
asked by anonymous 18.02.2018 / 16:02

2 answers

0

As lstDeposit has the warehouses, you can order and get the last log:

var armazen = lstDeposito.OrderByDescending(x => x.Prazo).Take(1);

int menorprazo = armazen.prazo;
    
18.02.2018 / 23:03
0

I have done some tests here, and your code returns the smallest value correctly, I have tested other tables, but the idea is the same:

var valorMenorSalario = context.Funcionarios
                  .Where(x => x.Nome.Equals("Richard"))
                  .Min(x => x.Salario).Value;

In my case, I have more employees with the name Richard but I'm taking the smallest of the salaries between them.

19.02.2018 / 04:50