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:
01649232
Views:
46
Likes (1)
>
>        public static void GetTransactions()
>        {
>            using (var context = new PICSEntities(Config.model.SqlServer))
>            {
>                var q = from p in context.Parcels
>                        join pt in context.ParcelInventoryTypes on p.ParcelInventoryTypes_Id equals pt.ParcelInventoryTypes_Id
>                        join t in context.TransactionDetails on p.Parcels_Id equals t.Parcels_Id
>                        join h in context.TransactionHeaders on t.TransactionHeaders_Id equals h.TransactionHeaders_Id
>                        join g in context.GoodsTypes on p.GoodsTypes_Id equals g.GoodsTypes_Id
>                        join tt in context.TransactionTypes on h.TransactionTypes_Id equals tt.TransactionTypes_Id
>                        select new
>                        {
>                            Parcels_Id = p.Parcels_Id,
>                            Goods = g.Description,
>                            Inventory = pt.Description,
>                            RSReference = p.RSReference,
>                            Transaction_Nr = h.TransactionHeaders_Id,
>                            Transaction_Type = tt.TransactionTypes_Id,
>                            Date = h.TransactionDate,
>                            Weight = t.Weight,
>                            Amount = t.Amount
>                        };
>                // Json.serialize(q, @"c:\docs\q.json");
>                Monitor.Console($"Extracted {q.Count()} records.");
>                using (var fs = new System.IO.FileStream(@"c:\docs\q.xml", System.IO.FileMode.Create))
>                {
>                    System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(q.GetType());
>                    x.Serialize(fs, q);
>                }
>            }
>        }
>
>This breaks here :
>
>                    System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(q.GetType());
>
>Cannot serialize anonymous types.
>Is there a way around this?

Can you have a class instead of using new anonymous type?
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform