【发布时间】:2015-06-04 11:38:49
【问题描述】:
我有一个类似下面的表格条目,
ColumnA ColumnB ColumnC ColumnD
16 651 a European Union
16 651 x Membership
17 651 a Great Britain
17 651 x Economic integration
18 651 a European Union countries
18 651 x Economic integration
结果列表
ColumnA ColumnB
651 |a European Union|x Membership
651 |a European Union countries|x Economic integration
651 |a Great Britain|x Economic integration
想法是将3列分组,即ColumnA,ColumnB,ColumnC和Concatenate ColumnD。
到目前为止我已经做到了
var sub = (from x in db.Bs
where x.BId == BId
group x by new { x.BId, x.Sd, x.TNo, x.Tr } into g
select new Book
{
Tagno = g.Key.TNo,
value = " |" + g.Key.Sd + " " + g.Key. // I am not able to get the Value column here.
});
【问题讨论】:
-
因为它是分组的,我们可以使用下面的语法 g.Select(exp=>exp.ValueColumn) 获取该组下的值列表。
-
抛出异常
Values of type 'collection[Edm.String(Nullable=True,DefaultValue=,MaxLength=Max,Unicode=True,FixedLength=False)]' can not be converted to string." -
您需要使用 string.join("|",g.Select(exp=>exp.ValueColumn)) 因为分组结果将是一个列表,我们需要使用 string.join 进行连接列表中的值
-
实体框架不支持
String.Join -
有什么问题吗? String.Join 与实体框架无关,我们所做的与我们将如何使用加入字符加入集合的方式相同
标签: c# entity-framework