开发者

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

开发者 https://www.devze.com 2023-04-09 20:05 出处:网络
I have a member table with columns memberid Firstname( values like jo开发者_运维百科hn,pop...)

I have a member table with columns

 memberid
 Firstname( values like jo开发者_运维百科hn,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..


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消