数据库表为
child:
id name parentid
1 cnlbogs 1
2 happy 1
parent:
parentid name
1 parent1
实体类为:
public class Child
{
public string id { get; set; }
public string name{ get; set; }
public string parent_id { get; set; }
public Parent Parent { get; set; }
}
public class Parent
{
public string parentid { get; set; }
public List<Child> Childs { get; set; }
}
代码为:
//获取数据库数据
DataTable dtChild=GetChildTable();
DataTable dtParent=GetChildTable();
AutoMapper.Mapper.Reset();
AutoMapper.Mapper.CreateMap<IDataReader, Child>();
AutoMapper.Mapper.CreateMap<IDataReader, Parent>();
//映射实体,可以获取正确的数据,但是子类的Parent和父类的List<Child>应该怎么获取呢?
var resultChild = AutoMapper.Mapper.Map<IDataReader, IList<Child>>(dtChild.CreateDataReader());
var resultParent = AutoMapper.Mapper.Map<IDataReader, IList<Parent>>(dtParent.CreateDataReader());
谢谢,但是子类的Parent和父类的List<Child>应该怎么获取呢?