I have following query,
var employees = from emp in this.DataWorkspace.v2oneboxData.me_employees
where emp.me_is_deleted.Value == false && emp.me_is_manager == true
select new{emp.me_first_name,emp.me_last_name,emp.me_pkey};
I want to give a specific name to emp.me_first_name column, just like we do in SQL Queries like:
select emp_first_Name as "First Name" from me_employees
how to do it in linq queries ???
also is it possible to combine firstName and lastname in select query in Linq ? just like we do in SQL Queries like :
select me_first_name + ' ' + me_last_name as 'Full Name' from me_employee
how can i achieve this task in linq?
Thanks
You can't make it First Name
as that isn't a valid identifier, but you can use:
select new { FirstName = emp.me_first_name,
LastName = emp.me_last_name,
Key = emp.me_pkey };
Basically the property name in the anonymous type only defaults to whatever property you're using as the value - you can specify it yourself, but it has to be a valid C# identifier.
Or for the combination:
select new { FullName = emp.me_first_name + " " + emp.me_last_name,
Key = emp.me_pkey };
var list = fro e in emp
select new { FullName = e.Firstname + " " + e.LastName }
One of the example but its with the group by
Check more at : Learn SQL to LINQ (Visual Representation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With