Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XML Anonymous Types
Message
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Network:
Windows Server 2016
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01649231
Message ID:
01649378
Views:
25
>>Thanks. I found that using Reflection I was able to have my ExcelWrapper SaveLinq Of T. Turned out easier than I thought.
>>
>>Slightly off topic and as Cetin pointed out to me, I should make use of the relationships so my Linq now looks like this:
>>
>>        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
>>                         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 = t.TransactionHeader.RSTransactions.FirstOrDefault().RSTransactionType.Description ?? "",
>>                             RS_Document = t.TransactionHeader.RSTransactions.FirstOrDefault().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);
>>                }
>>            }
>>        }
>>
>>
>>This now works fine. I am a little bit worried about this though:
>>
>>
>>                            RS_Type = t.TransactionHeader.RSTransactions.FirstOrDefault().RSTransactionType.Description ?? "",
>>                             RS_Document = t.TransactionHeader.RSTransactions.FirstOrDefault().Document ?? "",
>>
>>
>>There is a 1 to M relation between TransactionHeaders and RSTransactions. But I'm really only interested in the first record, but I need two fields (Description and Document). The fact that I issue twice FirstOrDefault does not look right.
>>
>>Many thanks for your help.
>
>Don't see an easy way of avoiding the duplication but the code should be fine. But if TransactionHeader can have NO RSTransactions you will get an exception (ditto if no EMTransactions)

Nono, it works fine. Coalescence ?? "" ?.

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform