2

I have a member table with columns

 memberid
 Firstname( values like john,pop...)
 secondname(values like ..david ,rambo..)

i want to get the firstname and secondname in a single query

i want something like this..

john david
pop rambo 

i know how to do in mysql like this..

  string sql = select (Firstname,'',secondname) as fullname from members...

but i dont know how to get the full name using linq to entities ...

my entity name is dbcontext

would any one help on this..

Many thanks In advance..

Glory Raj
  • 17,397
  • 27
  • 100
  • 203

2 Answers2

3

You can simply use C# string manipulation:

List<string> names =  from m in ctx.members
    select m.firstname + ' ' + m.secondname;

Or use a more elaborate function to handle missing names etc.

H H
  • 263,252
  • 30
  • 330
  • 514
3
from m in member
select new {
             FULLNAME = String.Concat(m.Firstname+" ", m.secondname)       
}
Bastardo
  • 4,144
  • 9
  • 41
  • 60