POCO EF嵌套类的WCF序列化
本文关键字:WCF 序列化 EF 嵌套 POCO | 更新日期: 2023-09-27 18:01:38
我有一个问题。我有一个WCF服务作为我的数据访问我的实体框架。我需要返回一些对象。这是我的第一个模型:
[DataContract(IsReference = true)]
public partial class Osoba
{
[DataMember]
public int IdOsobe { get; set; }
[DataMember]
public string PrezimeOsobe { get; set; }
[DataMember]
public string ImeOsobe { get; set; }
[DataMember]
public virtual Partner Partner { get; set; }
}
这是我的第二个模型:
[DataContract(IsReference = true)]
public partial class Partner
{
public Partner()
{
this.Dokument = new HashSet<Dokument>();
}
[DataMember]
public int IdPartnera { get; set; }
[DataMember]
public string OIB { get; set; }
[DataMember]
public int TipPartnera { get; set; }
[DataMember]
public Nullable<int> IdMjestaSjedista { get; set; }
[DataMember]
public string AdrSjedista { get; set; }
[DataMember]
public Nullable<int> IdMjestaIsporuke { get; set; }
[DataMember]
public string AdrIsporuke { get; set; }
[DataMember]
public virtual ICollection<Dokument> Dokument { get; set; }
[DataMember]
public virtual Mjesto Mjesto { get; set; }
[DataMember]
public virtual Mjesto Mjesto1 { get; set; }
[DataMember]
public virtual Osoba Osoba { get; set; }
[DataMember]
public virtual Tvrtka Tvrtka { get; set; }
}
当我的服务返回Osoba时,Partner引用对象没有序列化。Partner = null。我做错了什么?我尝试过ServiceKnownType属性,没有。
我已经做到了。代理不是问题,因为我使用它作为我的代理http://msdn.microsoft.com/en-us/library/vstudio/ee705457(v=vs.100).aspx问题是EF - context.Entry(e)中的一行代码。状态= EntityState.Detached。每个包含的实体实际上都是分离的。我对此发表了评论,一切都很顺利。非常感谢大家