English 中文(简体)
Converting IQueryable<object> results to comma delimited string
原标题:

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?

最佳回答

You can to use String.Join to create your comma delimited string.

string DetailsOfSickness = 
    String.Join(", ", (
      from t2 in illnesses
      join ai1 in absenceIllnesses on t2.IllnessID equals ai1.IllnessID
      select t2.IllnessName).ToArray());
问题回答

Something like this should do it:

DetailsOfSickness = String.Join(", ", (
  from t2 in Illnesses
  join ai1 in AbsenceIllnesses on t2.IllnessID equals ai1.IllnessID
  select t2.IllnessName).ToArray());
  • Please be aware, non-compiler, non-tested code.




相关问题
IQueryable into a hierarchy

I currently have an IQueryable of Questions. In my Question object I have and "id" and a "parentId" which can be used to create a hierarchy. Currently, I bind a RadTreeView to the IQueryable of ...

sorting of an Iqueryable

I have an IQueryable with duplicate entries and I want to sort this IQueryable by the count of occurrences.

Determine the position of an element in an IQueryable

I have a IQueryable which is ordered by some condition. Now I want to know the position of a particular element in that IQueryable. Is there a linq expression to get that. Say for example there are ...

Linq-Sql IQueryable<T> and chaining OR operations

I m trying to simulate: WHERE x.IsActive = true OR x.Id = 5 The following causes AND to be used... how do I simulate an OR condition with IQueryable (qry) and my nullable int, given that other ...

Linq, Where Extension Method, Lambda Expressions, and Bool s

Greetings, I am having some issues with using a bool operation within a Where clause extension method of an IQueryable object obtained using Linq to Entities. The first example is showing what does ...

Linq - How to turn IQueryable<IEnumerable> into IQueryable

I have a simple linq statement that isn t quite returning what I would like. I understand why, I just don t know how to wriet it to get what I want. The query is as follows: answers = from a in ents....

热门标签