当我返回IEnumerable<ProgramRange>
异常时:
基础连接已关闭:连接意外关闭。
ProgramRange 类如下所示:
[DataContract]
public partial class ProgramRange
{
public ProgramRange()
{
this.GradeVariants = new HashSet<GradeVariant>();
}
[DataMember]
public int ID { get; set; }
[DataMember]
public int Range { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public virtual ICollection<GradeVariant> GradeVariants { get; set; }
}
该系列仅包含八项,因此我认为这<dataContractSerializer maxItemsInObjectGraph="2147483647" />
不是经常建议的。
当我从上下文中获取数据时,.ToList()
它不可能是这样的:
public IEnumerable<ProgramRange> GetAll()
{
using (Entities dbContext = new Entities())
{
return dbContext.ProgramRanges.ToList();
}
}
我尝试在实现中将 ProgramRange 类添加到您的服务的已知类型:
[ServiceBehavior]
[ServiceKnownType(typeof(ProgramRange))]
public class ValidationService : IValidationService
我已经尝试返回其他一些东西来测试:(ProgramRange
有效),IEnumerable<string>
(有效),List<ProgramRange>
(无效)
我知道在stackowerflow上有几个关于这个主题的问题,我尝试了很多建议,但我无法让它发挥作用。
编辑:
这是 GradeVariant 类:
[DataContract]
public partial class GradeVariant
{
public GradeVariant()
{
this.GradeVariantRules = new HashSet<GradeVariantRule>();
}
[DataMember]
public int ID { get; set; }
[DataMember]
public int GradeTypeID { get; set; }
[DataMember]
public int ProgramRangeID { get; set; }
[DataMember]
public Nullable<int> ProgramID { get; set; }
[DataMember]
public Nullable<int> ApprenticeID { get; set; }
[DataMember]
public Nullable<int> Prefix { get; set; }
[DataMember]
public Nullable<bool> IV { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public virtual GradeType GradeType { get; set; }
[DataMember]
public virtual ProgramRange ProgramRange { get; set; }
[DataMember]
public virtual ICollection<GradeVariantRule> GradeVariantRules { get; set; }
}