pep30cula
شنبه 08 آذر 1393, 14:27 عصر
سلام
من یک مدل دارم که بصورت زیر تعریف شده:
public class Category{
public int Id { get; set; }
public int ParentCategoryId { get; set; }
public string ChildIDs { get; set; }
}
میخوام بصورت بازگشتی فیلد ChildIDs رو با همه ID های فرزند پر کنم. مثل این: 7,17,19,22,36
من با کوئری زیر فقط تونستم که فرزندان سطح اول رو برگردونم
from cg in db.Categorieswhere cg.Id == id
join urc in
(from x in db.UrlRecords where x.EntityName == "Category" select x) on cg.Id equals urc.EntityId into urccg
from f in urccg.DefaultIfEmpty()
select new
{
cg,
f,
ParentCategoryId = cg.ParentCategoryId,
ChildIds = string.Join(",", (from x in db.Categories where x.ParentCategoryId == cg.Id select x.Id))
}
این سوال رو در stackoverflow هم مطرح کردم و هنوز پاسخی دریافت نکردم
http://stackoverflow.com/questions/27185555/recursively-select-all-child-ids-and-join-in-one-string-using-linq
من یک مدل دارم که بصورت زیر تعریف شده:
public class Category{
public int Id { get; set; }
public int ParentCategoryId { get; set; }
public string ChildIDs { get; set; }
}
میخوام بصورت بازگشتی فیلد ChildIDs رو با همه ID های فرزند پر کنم. مثل این: 7,17,19,22,36
من با کوئری زیر فقط تونستم که فرزندان سطح اول رو برگردونم
from cg in db.Categorieswhere cg.Id == id
join urc in
(from x in db.UrlRecords where x.EntityName == "Category" select x) on cg.Id equals urc.EntityId into urccg
from f in urccg.DefaultIfEmpty()
select new
{
cg,
f,
ParentCategoryId = cg.ParentCategoryId,
ChildIds = string.Join(",", (from x in db.Categories where x.ParentCategoryId == cg.Id select x.Id))
}
این سوال رو در stackoverflow هم مطرح کردم و هنوز پاسخی دریافت نکردم
http://stackoverflow.com/questions/27185555/recursively-select-all-child-ids-and-join-in-one-string-using-linq