有没有一种方法可以轻松地将平面 DataTable 转换为嵌套的 .NET 对象? [英] Is there a way to easily convert a flat DataTable to a nested .NET object?
问题描述
我有一个大型手动调整的 SQL 查询,它返回一个包含许多 (>25) 列的平面数据表.
I have a large hand tuned SQL query that returns a flat data table with many (>25) columns.
目前,我手动将其转换为具有三级嵌套的 .NET 对象(即,一个对象包含(在其他属性中)一个进一步对象列表,其中包含(在其他属性中)一个进一步对象列表.
Currently, I manually convert that to a .NET object with three levels of nesting (i.e. an object which contains (among other properties) a list of further objects which contains (among other properties) a list of further objects.
有没有像 AutoMapper 这样的东西可以轻松地将 DataTable 转换为目标 .NET 对象,即使它是嵌套的?
Is there anything with the ease of something like AutoMapper which can convert a DataTable into a target .NET object, even if its nested?
推荐答案
我是这个问题的原发帖者.
I am the original poster of this question.
事实证明我问错了问题:我应该问如何轻松执行映射到复杂 POCO 排列的快速查询.
It turns out that I was asking the wrong question: I should have been asking how to easily perform fast queries which map into a complex arrangement of POCOs.
我发布了最适合我的解决方案,请参阅 如何在 Dapper.Net 中编写一对多查询? 以及引用 Dapper + Slapper.Automapper 的答案.
I have posted the solution that worked perfectly for me, see How do I write one to many query in Dapper.Net? and the answer that references Dapper + Slapper.Automapper.
这篇关于有没有一种方法可以轻松地将平面 DataTable 转换为嵌套的 .NET 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!