How do I concatenate strings in Entity Framework Query?

前端 未结 2 1834
名媛妹妹
名媛妹妹 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:38

    You have to execute the query before projecting. Otherwise EF tries to translate the Join method into SQL (and obviously fails).

    var results = this.context
                      .Farms
                      .ToList()
                      .Select(f => new
                          {
                              f.Id, 
                              Fruits = string.Join(", ", f.Fruits)
                          });
    

提交回复
热议问题