> RS_Type = t.TransactionHeader.RSTransactions.FirstOrDefault().RSTransactionType.Description ?? "", > RS_Document = t.TransactionHeader.RSTransactions.FirstOrDefault().Document ?? "", >>
public static void GetTransactions() { using (var context = new PICSEntities(Config.model.SqlServer)) { var q = (from p in context.Parcels join t in context.TransactionDetails on p.Parcels_Id equals t.Parcels_Id let firstTransaction = t.TransactionHeader.RSTransactions.FirstOrDefault() select new { Parcels_Id = p.Parcels_Id, Goods = p.GoodsType.Description, Inventory = p.ParcelInventoryType.Description, RSReference = p.RSReference, Transaction_Nr = t.TransactionHeaders_Id, Transaction = t.TransactionHeader.TransactionType.Description, Date = t.TransactionHeader.TransactionDate, Weight = t.Weight, Amount = t.Amount, EM_Document = t.TransactionHeader.EMTransactions.FirstOrDefault().Document ?? "", EM_Count = t.TransactionHeader.EMTransactions.Count(), RS_Type = firstTransaction.RSTransactionType.Description ?? "", RS_Document = firstTransaction.Document ?? "", RS_Count = t.TransactionHeader.RSTransactions.Count() }).ToList(); using (var xl = new ExcelWrapper()) { xl.wb = xl.wbs.Add(); xl.ws = xl.wb.ActiveSheet; string filename = SequencedFilename.get(@"c:\docs\Parcels", $".xlsx"); xl.SaveLinq(q, filename); } } }As per the ExcelWrapper, I think you wouldn't need reflection, if you use Epplus library from Nuget, you could save any collection to Excel (with or without excel being installed). It is not very fast as it claims but not slow either. Here is a sample:
ExcelPackage pck = new ExcelPackage(); var wsEnum = pck.Workbook.Worksheets.Add("MyData"); wsEnum.Cells["A1"].LoadFromCollection(myCollection, true, TableStyles.Medium9); wsEnum.Cells[wsEnum.Dimension.Address].AutoFitColumns(); var fi = new FileInfo(@"c:\temp\ExcelSample.xlsx"); if (fi.Exists) { fi.Delete(); } pck.SaveAs(fi);