C# 使用LINQtoEntities和XSD创建嵌套XML文档
我正在尝试使用LINQtoEntities从SQL数据源创建XML文档。我使用XSD为XML文档创建类。XML结构如下(部分列表):C# 使用LINQtoEntities和XSD创建嵌套XML文档,c#,xml,linq,xsd,entities,C#,Xml,Linq,Xsd,Entities,我正在尝试使用LINQtoEntities从SQL数据源创建XML文档。我使用XSD为XML文档创建类。XML结构如下(部分列表): 098098 出境 预付款 SEFL LTL 100283534 098098 2004-03-19T15:35:00 1. 1. 123456 ABC公司。 大街354号 01234 美国 下面是我用来填充类的代码,以便将其序列化为XML文件: List<ExecutedShipment> Shipments = new List<
098098
出境
预付款
SEFL
LTL
100283534
098098
2004-03-19T15:35:00
1.
1.
123456
ABC公司。
大街354号
01234
美国
下面是我用来填充类的代码,以便将其序列化为XML文件:
List<ExecutedShipment> Shipments = new List<ExecutedShipment>();
Shipments = (
from sh in ShipData.shiphead
where sh.shipdate >= Yesterday && sh.shipdate <= Yesterday
select new ExecutedShipment
{
ExecutedShipmentIdentifier = SqlFunctions.StringConvert((double)sh.packnum),
ShipDirection = "Outbound",
FreightTerms = "Pre-Paid",
CarrierSCAC = sh.shipviacode,
EquipmentType = "LTL",
CarrierTrackingNumber = sh.trackingnumber,
LoadList = new ExecutedShipmentLoadListLoad
{
ExecutedLoadIdentifier = SqlFunctions.StringConvert((double)sh.packnum),
DropoffSequenceNumber = "TEST"
//Schedule = (new ExecutedShipmentLoadListLoadScheduleActualShipDate
// {
// timezone = "EST",
// Value = "0000-00-00" //sh.shipdate
// }).ToArray()
}
}).ToList<ExecutedShipment>();
列表装运=新列表();
装运=(
来自ShipData.shiphead中的sh
其中sh.shipdate>=beday&&sh.shipdate您只需创建一个数组并将实例放入数组声明中,如下所示:
// Start array declaration.
LoadList = new [] {
// First element.
new ExecutedShipmentLoadListLoad {
ExecutedLoadIdentifier = SqlFunctions.StringConvert((double)sh.packnum),
DropoffSequenceNumber = "TEST"
//Schedule = (new ExecutedShipmentLoadListLoadScheduleActualShipDate
// {
// timezone = "EST",
// Value = "0000-00-00" //sh.shipdate
// }).ToArray()
}
// Other elements here.
// End array declaration
}
您只需创建一个数组并将实例放入数组声明中,如下所示:
// Start array declaration.
LoadList = new [] {
// First element.
new ExecutedShipmentLoadListLoad {
ExecutedLoadIdentifier = SqlFunctions.StringConvert((double)sh.packnum),
DropoffSequenceNumber = "TEST"
//Schedule = (new ExecutedShipmentLoadListLoadScheduleActualShipDate
// {
// timezone = "EST",
// Value = "0000-00-00" //sh.shipdate
// }).ToArray()
}
// Other elements here.
// End array declaration
}