相关疑难解决方法(0)

使用C#/ Linq将展平的分层数据从SQL Server转换为结构化JSON对象

我正在开发一个MVC应用程序,它从SQL Server中的表中检索数据,结构如下:

+-----------------------------------+
| Id | Name   | Hierarchy   | Depth |
|-----------------------------------|
| 01 | Justin | /           |     0 |
| 02 | Chris  | /1          |     1 |
| 03 | Beth   | /1/1        |     2 |
+-----------------------------------+
Run Code Online (Sandbox Code Playgroud)

Hierarchy列中的示例数据是hierarchyid数据类型的字符串表示形式,并Depth使用该hierarchyid::GetLevel()方法计算列.

使用Entity Framework 4.1,我已将上表映射到此类:

public class Node {
    public int Id { get; set; }
    public string Name { get; set; }
    public string HierarchyPath { get; set; } // String representation …
Run Code Online (Sandbox Code Playgroud)

linq asp.net-mvc json entity-framework

3
推荐指数
1
解决办法
6294
查看次数

标签 统计

asp.net-mvc ×1

entity-framework ×1

json ×1

linq ×1