Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XML Anonymous Types
Message
Information générale
Forum:
ASP.NET
Catégorie:
XML
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Network:
Windows Server 2016
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01649231
Message ID:
01649232
Vues:
47
J'aime (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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform