Search code examples
entity-framework-4

How to write SQL query to LINQ using Lambda Expression?


Here is Simple SQL query... I want to get selected field not all table fields by Using Entity frame work List function.

"Select CustName, CustEmail, CustAddress, CustContactNo  from Customers"

Solution

  • I assume you already have a context defined and table mapped.

    var results = dbContext.Customers.Select(x => new { x.CustName, x.CustEmail, x.CustAddress, x.CustContactNo }).ToList();