Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do this SELECT statement that uses column renaming (or column alias) with LINQ?

Tags:

linq

How do I get 'anotherColumnName' in LINQ?

SELECT thisColumnName as anotherColumnName FROM TableName

I have the following which obviously gives me 'thisColumnName' not 'anotherColumnName'

    var query = from names in _context.TableName
                select names;
    return query.ToList();
like image 809
Paul Rowland Avatar asked Jan 24 '23 20:01

Paul Rowland


1 Answers

Use an anonymous type:

var query = (from name in _context.Table
            select new { anotherColumnName = name.ColumnName });

Good luck!

like image 99
Ian P Avatar answered May 17 '23 03:05

Ian P