/// <summary> /// 父类迭代子类返回实体 /// </summary> /// <param name="root"></param> /// <param name="all"></param> /// <param name="currentModel"></param> public static void Recursion(CardType root, List<CardType> all,CardTypeModel currentModel = null) { currentModel = Mapper.Map<CardType, CardTypeModel>(root); var subs = all.Where(n => n.Parent.Id == currentModel.Id); foreach (var cardType in subs) { if (currentModel.SubCardTypeModels == null) { currentModel.SubCardTypeModels = new List<CardTypeModel>(); } currentModel.SubCardTypeModels.Add(Mapper.Map<CardType, CardTypeModel>(cardType)); Recursion(cardType, all, currentModel); } }
public void Insert(CardType cardType) { DbContext.CardTypes.Add(cardType); DbContext.SaveChanges(); }