我有两个班:
Lookup
和
LookupItem
那个
查找
名为的成员
Items
这是一个集合
查找项
我无法序列化
查找
或
查找项
. 第一次出错
The type LookupItem was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
第二次我出错了
A circular reference was detected while serializing an object of type Lookup.
.
我怎样才能解决这个问题?
我使用以下代码进行序列化:
public static string Serialize(object obj)
{
XmlSerializer ser = new XmlSerializer(obj.GetType());
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
ser.Serialize(writer, obj);
return sb.ToString();
}
更新:
课程框架:
[活动记录(lazy=true)]
公共类查找:ActiveRecordExtender,IComparable
{
公共查找()
{
}
[Property]
public virtual string Title { set; get; }
// creating relation
[HasMany(typeof(LookupItem), Cascade = ManyRelationCascadeEnum.All)]
public virtual IList Items { set; get; }
}
[活动记录(lazy=true)]
公共类LookupItem:ActiveRecordExtender
{
公共查找项()
{
}
//creating relation
[BelongsTo("Lookup_ID")]
public virtual Lookup ContainerLookup { set; get; }
[Property]
public virtual string Title { set; get; }
[Property]
public virtual string Value { set; get; }
[Property]
public virtual int SortOrder { set; get; }
}
请注意,我正在使用Catle ActiveRecord作为ORM,请注意,此问题与继承无关。
ActiveRecordBase
. 因为这个域中没有关系的其他类工作正常。