Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XML Anonymous Types
Message
De
27/03/2017 04:30:20
 
 
À
26/03/2017 08:18:41
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
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:
01649362
Vues:
36
If TransactionDetails and Parcels don't have a lot of surplus fields you can save some typing:
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 {p,t};


XDocument asXmlDocument =
new XDocument(
	new XDeclaration("1.0", "utf-8", ""),
		new XElement("Parcels",
		  from p in q.AsEnumerable()
		  select new XElement("Parcel",
			  new XAttribute("Parcels_Id", p.p.Parcels_Id),
			  new XAttribute("Goods", p.p.GoodsType.Description),
			  new XAttribute("Inventory", p.p.ParcelInventoryType.Description),
			  new XAttribute("RSReference", p.p.RSReference),
			  new XAttribute("Transaction_Nr", p.t.TransactionHeaders_Id),
			  new XAttribute("Transaction_Type", p.t.TransactionHeader.TransactionType.Description),
			  new XAttribute("Date", p.t.TransactionHeader.TransactionDate),
			  new XAttribute("Weight", p.t.Weight),
			  new XAttribute("Amount", p.t.Amount)
			)
		)
	);
	using (XmlWriter xw = XmlWriter.Create(@"c:\docs\q.xml"))
	{
		asXmlDocument.Save(xw);
	}
}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform