how to convert parent object with child object list into xml file using c#?
1.I have a parent table Class () and a child table subject . I have
created object of these classes and child object added as a list in parent
class . Now i want to read a parent table data using linq and convert it
into xml file . I am trying xml serialize for that . Below is my code.
1) ClassMaster cls = new ClassMaster();List clsList =
cls.FindAll().Where(t => t.ClassSymbol == "I").ToList();var serializer1 =
new XmlSerializer(cls.FindAll().GetType()); 2)ClassMaster cls = new
ClassMaster(); var stringwriter = new System.IO.StringWriter(); var
serializer = new XmlSerializer(cls.GetType());
serializer.Serialize(stringwriter, cls); But its throwing a exception in
line 3 "Cannot serialize member
'School.Objects.ClassMaster.classSubjectList' of type
'System.Collections.Generic.IList`1[[School.Objects.ClassWiseSubject,
School.Objects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'"
public class ClassMaster : GenericRepository { public virtual int ClassId
{ get; set; }
public virtual string ClassSymbol { get; set; }
public virtual string ClassName { get; set; }
public virtual IList<ClassWiseSubject> classSubjectList { get; set; }
}
public class ClassWiseSubject : GenericRepository<ClassWiseSubject>
{
public virtual int Id { get; set; }
public virtual int ParentID { get; set; }
public virtual int SerialNo { get; set; }
public virtual string SubjectCode { get; set; }
}
HBM config file :
<class name="SubjectMaster" table="tbl_SubjectMaster">
<id name="SubjectId" column="SubjectId" type="int">
<generator class="identity"></generator>
</id>
<property name="SubjectCode" column="SubjectCode" type="string"/>
<property name="SubjectName" column="SubjectName" type="string"/>
</class>
Thanks Surajit
No comments:
Post a Comment