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 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.
精彩评论