locked
EF6 Required Syntax? RRS feed

  • Question

  • User-173651909 posted

    I wanted to confirm something. In MVC when running a query such as:

    var test = (from x from db.table1
                where x.id == 1
                select x.name).FirstOrDefault();
    
    var test2 = (from y from db.table1
                where y.id == 2
                select y.Description).FirstOrDefault();
    
    var test3 = (from z from db.table2
                where z.id == 3
                select z.somethingelse).FirstOrDefault();

    If I was to perform the above is it possible to use the same letter as an alias (x for example) as opposed to changing with each query (x, y, z).

    Thanks in advance
    Adam

    Thursday, February 4, 2016 2:28 PM

Answers

  • User-821857111 posted

    You can re-use the same variable name. It is a range variable and is only applicable within the scope of the individual query. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 4, 2016 3:09 PM