Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XML Anonymous Types
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
XML
Titre:
XML Anonymous Types
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:
01649231
Vues:
74
        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?

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform