继续, Map xml string property to C# properties
我有一个IQueryable Source,它需要与xml字符串属性的映射一起映射到IQueryable Destination类。 我尝试使用下面的资源,但是不起作用,
Mapper.Initialize(cfg =>
cfg.CreateMap<Source, Destination>()
.ConstructUsing(x => ConstructDestination(x)));
static Destination ConstructDestination(Source src)
{
XDocument xdoc = new XDocument();
xdoc = XDocument.Parse($"<Root>{src.Address}</Root>");
return new Destination
{
Country = xdoc.Root.Element(nameof(Destination.Country)).Value,
City = xdoc.Root.Element(nameof(Destination.City)).Value,
Prefecture = xdoc.Root.Element(nameof(Destination.Prefecture)).Value,
};
}
IQueryable<Destination> destQuery = srcQuery.ProjectTo<Destination>();
var result1 = destQuery.ToList();