I am new to LinQ and those lambdas are appearing tricky to me :(
I have a table where there are two columns. First_Name and Last_name. I am populating a gridview using LinQ.
protected void Page_Load(object sender, EventArgs e)
{
myLinQtoSQLClassDataContext objDataContext = new myLinQtoSQLClassDataContext();
var allUserList = from CurrentUser in objDataContext.Users.Where(c => c.Is_Deleted != false)
select new
{
CurrentUser.First_Name,
CurrentUser.Last_Name,
CurrentUser.Email_ID,
CurrentUser.GUID
};
GridView1.DataSource = allUserList;
GridView1.DataBind();
}
I can retrieve the values using LinQ but I want to concatenate the first name and last name with a space in between.
The equivalent SQL query what I am trying to acchieve would be like this:
Select First_name + ' ' + Last Name as Username, Email_ID, GUID
From tbl_Users where Is_Deleted != false
How can I achieve this through the lambda expression?
You can use string concatenation:
select new
{
Username = CurrentUser.First_Name + " " + CurrentUser.Last_Name,
CurrentUser.Email_ID,
CurrentUser.GUID
};
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