Firstly you would map it a flat class. eg. db.Fetch<CategoryDb>("select * from categories");
public class CategoryDb {
public int Id { get; set; }
public string Name { get; set; }
public int ParentCategoryId { get; set; }
}
From here I would then create a new Object that self referenced itself. (You could use the existing object with the ParentCategory having the [Result] attribute on it.)
public class Category {
public int Id { get; set; }
public string Name { get; set; }
public Category ParentCategory { get; set; }
}
You could then take this and convert your flat list into a nested list. I do have code somewhere that can do this, and for which it also provides searching methods etc, but its not on this computer. I will update tomorrow with a link to the code.
发布评论
评论(1)
首先,您将其映射为一个平面类。例如。
db.Fetch("select * fromcategories");
从这里我将创建一个自引用自身的新对象。 (您可以使用具有 [Result] 属性的 ParentCategory 的现有对象。)
然后您可以将其转换为嵌套列表。
我确实在某处有可以执行此操作的代码,并且它还提供了搜索方法等,但它不在这台计算机上。我明天将更新代码链接。
Firstly you would map it a flat class. eg.
db.Fetch<CategoryDb>("select * from categories");
From here I would then create a new Object that self referenced itself. (You could use the existing object with the ParentCategory having the [Result] attribute on it.)
You could then take this and convert your flat list into a nested list.
I do have code somewhere that can do this, and for which it also provides searching methods etc, but its not on this computer. I will update tomorrow with a link to the code.