通过解决方法解决了问题:
我在模型中添加了 3 种复杂类型,与每个单独结果集的数据结构相匹配。此外,我在数据上下文之外添加了一个容器类,它使用复杂类型将数据保存在一个对象中。我使用自定义方法扩展了上下文类,以处理存储过程调用并将结果映射到适当的复杂类型。ObjectContext.Translate 有很大帮助... WCF 数据服务类使用虚拟 DataContext 实例化。这可以为我的自定义数据容器类创建元数据,现在可以将其用作自定义 WCF 数据服务方法的返回类型。调用方法时会实例化数据上下文。
数据容器类` public class BrfPackageDataContainer { public Guid TransactionId { get; 放; }
public List<BrfFlight> Flights {
get;
set;
}
public List<BrfFlight_Info> Flight_Infos {
get;
set;
}
public List<BrfInfo> Infos {
get;
set;
}
public BrfPackageDataContainer () {
this.Flights = new List<BrfFlight>();
this.Flight_Infos = new List<BrfFlight_Info>();
this.Infos = new List<BrfInfo>();
}
}`
上下文扩展:公共部分类 FlightInfoEntities { 公共虚拟 BrfPackageDataContainer GetBrfPackage(int?credId,字符串 operatorCode,字符串离开,int?flightId,DateTime?stdRangeStart,DateTime?stdRangeEnd,字符串 requestingApplication,字符串 requestingComputerName,字符串 requestingACReg,ref Guid transactionId,int? specificInfoTypeId, byte?levelOfDetail, bool?skipLog) { using (DbCommand command = this.Database.Connection.CreateCommand()) { command.CommandType = CommandType.StoredProcedure; command.CommandText = "[dbo].[GetBrfPackage]";
...
var dataContainer = new BrfPackageDataContainer();
try {
this.Database.Connection.Open();
using (DbDataReader reader = command.ExecuteReader()) {
dataContainer.Flights = ((IObjectContextAdapter)this).ObjectContext.Translate<BrfFlight>(reader).ToList();
reader.NextResult();
dataContainer.Flight_Infos = ((IObjectContextAdapter)this).ObjectContext.Translate<BrfFlight_Info>(reader).ToList();
reader.NextResult();
dataContainer.Infos = ((IObjectContextAdapter)this).ObjectContext.Translate<BrfInfo>(reader).ToList();
}
return dataContainer;
} catch (Exception ex) {
throw ex;
}
}
WCF 数据服务方法:
[WebGet]
[SingleResult]
public BrfPackageDataContainer GetBrfPackage () {
using (var brfCtx = new FlightInfoEntities()) {
Guid transactionId = new Guid();
var brfPackageDataContainer = brfCtx.GetBrfPackage(null,"4T",null,null,null,null,"test",Environment.MachineName,null,ref transactionId,null,3,false);
return brfPackageDataContainer;
}
}