我有下面的 linq 查询
var dd = (from dt in d
select new
{
dt.id,
dt.date,
dt.customerid,
dt.customer,
dt.Description,
dt.defect,
dt.address,
products = string.Join(",", dt.products)
}).ToList();
string.Join
不起作用,错误是
LINQ to Entities does not recognize the method '
System.String Format(System.String, System.Object, System.Object)
'
我用 Google 搜索了很多,但找不到任何其他解决方案。我想做的是,dt.Products 是一个数组,我想将它们全部连接到一个字符串中。在 Linq to Entities 中可能吗?
最佳答案
您无法在查询中执行此操作,但可以通过调用 .AsEnumerable()
在内存中执行此操作。第一的。试试这个:
var dd =
(from dt in d
select new
{
dt.id,
dt.date,
dt.customerid,
dt.customer,
dt.Description,
dt.defect,
dt.address,
dt.products
})
.AsEnumerable()
.Select(dt => new {
dt.id,
dt.date,
dt.customerid,
dt.customer,
dt.Description,
dt.defect,
dt.address,
products = string.Join(",", dt.products)
}).ToList();
但请注意,如果您的数据集特别大,这可能会导致明显的性能影响。
关于c# - 如何在 Linq toEntity 中将字符串数组转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20004380/