EF数据库迁移命令 C#无限极递归树及三元运算符简写
程序员文章站
2022-05-31 09:19:13
...
1、EF数据库迁移控制台命令:
Enable-Migrations
Add-Migration init
update-database
2、C#三元运算符简写
is_seckill_activity ?is_seckill_activity :false
is_seckill_activity ?? false
3、C#无限极递归树
public JsonResult GetTreeMenuList()
{
var menuTreeList = authService.GetTreeMenuList(-1);
var treeList = new List<TreeListViewModel>();
foreach (var item in menuTreeList)
{
var temp = new TreeListViewModel()
{
id = item.id,
text = item.name,
pid = item.pid
};
treeList.Add(temp);
}
var treeItem = new TreeListViewModel()
{
id = 0,
text = "跟节点",
nodes = new List<TreeListViewModel>()
};
var result = BuildTreeList(treeList, treeItem);
return Json(result, JsonRequestBehavior.AllowGet);
}
private TreeListViewModel BuildTreeList(List<TreeListViewModel> all, TreeListViewModel curItem)
{
var subItems = all.Where(m => m.pid == curItem.id).ToList();
curItem.nodes = new List<TreeListViewModel>();
curItem.nodes.AddRange(subItems);
foreach (var subItem in subItems)
{
BuildTreeList(all, subItem);
}
return curItem;
}
上一篇: laravel无限极分类
下一篇: thinkphp 无限级分类