5

I have a LINQ query that returns all absences for an employee. The first part of the linq statement gets a basic list of the employees details, but I also return an IQueryable list of illnesses related to that absence.

I'd like to somehow convert that IQueryable list to a comma delimited list of Illnesses.

Currently I use (majorly stripped down):

DetailsOfSickness = (
  from t2 in Illnesses
  join ai1 in AbsenceIllnesses on t2.IllnessID equals ai1.IllnessID
  select new { Illness = ", " + t2.IllnessName })

Which returns the list but I'd like the results like: Headache, Flu, Cramps.... etc. Any ideas?


Using Where With SubSonic Collection

I am having problem with collection object. Here is the code

CarCollection obj=new CarCollection(); obj.Where("Id","10"); obj.Load();

The problem is the result of the records doubles i.e actually there is only 1 record with the id 10 but it returns 2 same records. Please Help me as i am a newbie.

Thanks

4

2 回答 2

9

您可以用来String.Join创建逗号分隔的字符串。

string DetailsOfSickness = 
    String.Join(", ", (
      from t2 in illnesses
      join ai1 in absenceIllnesses on t2.IllnessID equals ai1.IllnessID
      select t2.IllnessName).ToArray());
于 2009-12-08T11:39:58.703 回答
3

这样的事情应该这样做:

DetailsOfSickness = String.Join(", ", (
  from t2 in Illnesses
  join ai1 in AbsenceIllnesses on t2.IllnessID equals ai1.IllnessID
  select t2.IllnessName).ToArray());
  • 请注意,非编译器,未经测试的代码。
于 2009-12-08T11:44:31.300 回答