static void Main(string[] args) { using (var db = new aaContext2()) { Temp temp = new Temp(); var cc = db.Catagory.FirstOrDefault(); IList <Category> parentList = new List <Category>(); foreach (Category catagory in db.Catagory.Where(cat => cat.ParentId == null)) { parentList.Add(temp.Recursive(catagory.Id, catagory.Name)); } } }
static void Main(string[] args) { using (var db = new aaContext2()) { IList<DTO> dto = new List<DTO>(); dto = db.Table2.Select(a => new DTO { Name = a.Name, User = a.Namea.User, DateDifference = (DbFunctions.DiffDays(a.Date, db.Table2.Where(aa => aa.Name.Equals(a.Name) && a.Date < aa.Date).Min(dd => dd.Date) ) ?? (DbFunctions.DiffDays(db.Table1.Where(aa => aa.Name.Equals(a.Name)).Min(aaa => aaa.Date), a.Date))) }).ToList(); } }
public Category Recursive(long parentId, string name) { Category catagory = new Category(); catagory.Id = parentId; catagory.Name = name; using (var db = new aaContext2()) { //base condition if (db.Catagory.Where(catagory1 => catagory1.ParentId == parentId).Count() < 1) { return(catagory); } else { IList <Category> newCatagoryList = new List <Category>(); foreach (Category cat in db.Catagory.Where(cata => cata.ParentId == parentId)) { newCatagoryList.Add(Recursive(cat.Id, cat.Name)); } catagory.CatagoryList = newCatagoryList; return(catagory); } } }