3.3 创建 pr_GetLocations 存储过程:
CREATE PROCEDURE pr_GetLocations
AS
BEGIN
WITH locs(id,name,parent,loclevel)
AS
(
SELECT id,name,parent,0 AS loclevel FROM tb_loc
WHERE parent IS NULL
UNION ALL
SELECT l.id,l.name,l.parent,loclevel+1 FROM tb_loc l
INNER JOIN locs p ON l.parent=p.id
)
SELECT * FROM locs
END
3.4 在 Visual Studio 2008 里创建解决方案并新建一个网站。
3.5 在网站中添加 APP_Code 目录,并创建 Location 实体类,该类标识了所在地编号和名称,并且保存了父级所在地编号和它所包含的所有子所在地的集合:
public class Location
{
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
public LocationCollection SubLocations
{
get;
set;
}
public int ParentId
{
get;
set;
}
public Location()
{
Id = 0;
Name = string.Empty;
SubLocations = new LocationCollection();
ParentId=0;
}
}
本文来源:不详 作者:佚名