2013-11-15 65 views
2

我有以下如何将字符串数组转换为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(); 
LINQ查询

string.Join没有工作,错误的是

LINQ到实体无法识别方法 'System.String Format(System.String, System.Object, System.Object)'

我用谷歌搜索很多,并找不到任何其他解决方案。我想要做的是,dt.Products是一个数组,我想将它们连接在一起形成一个字符串。 Linq to Entities有可能吗?

回答

5

您不能在查询内做到这一点,但您可以先在内存中调用.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(); 

但是请注意,如果你的数据集是特别大,这可能会导致明显的性能影响。

相关问题