none
Get the maximum value saved from idventa linq RRS feed

  • Question

  • good afternoon

    Friends of the forum I'm trying to get the Max Idventa entered in a query linq I have a view that is called vi_venta_detalle

    This view arms a crystal report with different table and gives me the invoice that works

    My problem is I want to do the same but show the utlimo idventa entered

    This is what i have but it does not work

     public List<Vi_Ventas_Detalle> GetByMax(int IdVenta)
            {
                DAL.IRepository repository = new Modelo.Repository();
                try
                {
                    int maximo = repository.FindEntitySet<Vi_Ventas_Detalle>(x => true).Select(x => x.IdVenta).Max();
    
                    return maximo; error
    
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
    
            }
    

    I have an error in the return


    • Edited by djnilo Sunday, June 4, 2017 10:18 PM
    Sunday, June 4, 2017 10:17 PM

Answers

  • Cole Wu Thanks for taking  your time to read the problem
    But it was that he was passing a paramentro idventa bad he does not pass the to get the maximum so I stay the consultation

    public int GetByMax()
            {
                DAL.IRepository repository = new Modelo.Repository();
                try
                {
                    
                    int maximo = repository.FindEntitySet<Vi_Ventas_Detalle>(x => true).Max(x => x.IdVenta);
    
                    return maximo;
                    //foreach (var lista in Vi_Ventas_Detalle)
                    //{
                     
                    //}
                        
    
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
    
            }

    • Marked as answer by djnilo Wednesday, June 7, 2017 8:41 PM
    Wednesday, June 7, 2017 8:41 PM

All replies

  • Hi djnilo,

    According to your description and related code, the LINQ statement return the value of int, but the method need retrun a collection of Vi_Ventas_Detalle. please modify your code like this:

    public int GetByMax(int IdVenta)
            {
                DAL.IRepository repository = new Modelo.Repository();
                try
                {
                    int maximo = repository.FindEntitySet<Vi_Ventas_Detalle>(x => true).Select(x => x.IdVenta).Max();
    
                    return maximo; error
    
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
    
            }

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 5, 2017 6:11 AM
    Moderator
  • Cole Wu Thanks for taking  your time to read the problem
    But it was that he was passing a paramentro idventa bad he does not pass the to get the maximum so I stay the consultation

    public int GetByMax()
            {
                DAL.IRepository repository = new Modelo.Repository();
                try
                {
                    
                    int maximo = repository.FindEntitySet<Vi_Ventas_Detalle>(x => true).Max(x => x.IdVenta);
    
                    return maximo;
                    //foreach (var lista in Vi_Ventas_Detalle)
                    //{
                     
                    //}
                        
    
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
    
            }

    • Marked as answer by djnilo Wednesday, June 7, 2017 8:41 PM
    Wednesday, June 7, 2017 8:41 PM