我想在列表中合并列表的名称。错误消息:LINQ to Entities无法识别方法'System.String Join(System.String,System.String [])',并且该方法无法转换为商店表达式。
dgv.DataSource = this.oFacade.Context.Books
.Include(c => c.Categories)
.Select(c => new dtoObjectDGV
{
ID = c.ID,
Name = c.Name,
CategoryInfo= String.Join(", ", c.Categories.Select(d => d.Name).ToArray())
}).ToList();
结果:名称= C#书籍CategoryInfo = X类别,Y类别,... bla bla
Join
Linq to Entities不支持method,我建议您先投影所需的信息,然后使用AsEnumerable
扩展方法,可以切换到Linq to Object来使用Join
方法:
DataSource=this.oFacade.Context.Books
.Include(c => c.Categories)
.Select(c => new
{
ID = c.ID,
Name = c.Name,
Categories= c.Categories.Select(d => d.Name)
})
.AsEnumerable()
.Select(c => new dtoObjectDGV
{
ID = c.ID,
Name = c.Name,
CategoryInfo= String.Join(", ", c.Categories)
})
.ToList();
如果您的表不需要太多列,则可以考虑不进行第一个投影:
DataSource=this.oFacade.Context.Books
.Include(c => c.Categories)
.AsEnumerable()
.Select(c => new dtoObjectDGV
{
ID = c.ID,
Name = c.Name,
CategoryInfo= String.Join(", ", c.Categories.Select(d => d.Name).ToArray())
})
.ToList();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句