How do I concatenate strings in Entity Framework Query?

前端 未结 2 1846
名媛妹妹
名媛妹妹 2020-12-08 22:11

How do I concatenate strings in Entity Framework 4 I have a data from a column and I want to save as a string a comma separated string like \"value1, value2, value3\" Is the

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 22:40

    Took @Yakimych answer and thought would provide mine if someone needed:

    using (myDBEntities db = new myDBEntities())
                {
                    var results = db.Table
                        .ToList()
                        .Where(x => x.LastName.StartsWith("K"))
                        .Select(
                        x => new
                        {
                            x.ID,
                            Name = x.LastName + ", " + x.FirstName
                        }
                        );
    
                    lstCoaches.DataValueField = "ID";
                    lstCoaches.DataTextField = "Name";
                    lstCoaches.DataSource = results;
                    lstCoaches.DataBind();
                    ListItem item = new ListItem
                    {
                        Value = "0",
                        Text = "-- Make a Selection --"
                    };
                    lstCoaches.Items.Insert(0,item);
                    lstCoaches.SelectedIndex = 0;
                }
    

提交回复
热议问题