简体   繁体   中英

how to get two column values in a single query using linq to entities

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..

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.

from m in member
select new {
             FULLNAME = String.Concat(m.Firstname+" ", m.secondname)       
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM