0

I'm getting my collection from database

var exclCompany = companies.Select(u => new ExcelCompaniesViewModel
{
    Id = u.Id,
    IsEditedFirstTime = u.IsEditedFirstTime ? "Да" : "Нет",
    IsLoggedFirstTime = u.IsLoggedFirstTime ? "Да" : "Нет",
    Title = u.Title,
    Description = u.Description,
    Members = u.RmCompanyMembers.Select(p => new CompanyMemberViewModel
    {
        MemberDateLogin = "12/10/12",
        MemberName = String.Format("{0} {1} {2}", p.LastName, p.FirstName, p.MiddleName),
        TelephoneMemers = p.Phone
    }).ToArray()

}); 

and insert into worksheet.

workSheet.Cell(2, 1).InsertData(exclCompany);

But in result file, cells with members displayed as:

System.Linq.Enumerable+WhereSelectEnumerableIterator

How to insert collections with subcollections?

justcurious
  • 839
  • 3
  • 12
  • 29
Sergei
  • 21
  • 3
  • Do You must use `.ToArray()` at the end of the select? Can You `.ToList()` for example? – ntohl Oct 20 '15 at 11:23
  • System.Linq.Enumerable+WhereSelectEnumerableIterator is the type of exclCompany. You have to call .ToArray() or .ToList() to actually execute the LINQ query and retrieve the data. – Greg Oct 20 '15 at 11:33
  • I believe it's called. At the end of the `u.RmCompanyMembers.Select(...).ToArray()` – ntohl Oct 20 '15 at 11:36

1 Answers1

0

If You have access to modify the code to use .ToList(), and not .ToArray(), than You can use this:

Change the type of Members to something that implements the IList interface, and override the ToString() method. This way, You will have Your way to visualize an array. For example:

public class MembersCollection: IList<CompanyMemberViewModel>
...
    public override string ToString()
    {
        return string.Join(", ", this);
    }
}

And of course don't forget to implement the ToString() of CompanyMemberViewModel.

ntohl
  • 2,067
  • 1
  • 28
  • 32