Select Columns From ICollection RRS feed

  • Question

  • Hi,

    I have an ICollection and I want to export specific columns to Excel.

    Below is my code...

    ws.Cells["A1"].LoadFromCollection(myICollection.Select(from x in myICollection select x.UserID, x.Username), true);

    But I get this error...

    The type arguments for method 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,int,TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly

    Any ideas? Thanks!

    Monday, October 1, 2012 9:59 AM


  • The error does not concern with EF, it's a compire warning since the compiler it's not able to infer the correct type because of the Linq query.

    try change the code to the following:

    ws.Cells["A1"].LoadFromCollection(myICollection.Select(item => new { UserId = item.UserID, UserName = item.Username }), true);


    Monday, October 1, 2012 10:43 AM