gpt4 book ai didi

c# - 获取所有祖 parent ID 等于 1 的 child

转载 作者:太空狗 更新时间:2023-10-30 01:36:24 24 4
gpt4 key购买 nike

我在数据库中有如下三个表:

1.Design_Master_ParentMenus
1.ParentMenuID 1--------
2.Title |
2.Design_Master_Categories |
1.CategoryID 1------|---------
2.Title | |
3.ParentMenuID *------ |
3.Design_Master_TileItem |
1.TileItemID |
2.Title |
3.CategoryID *---------------

现在我想从祖 parent 的 ParentMenuID 等于 1 的 Master_Design_TileItem 中获取所有项目。

到目前为止,我已经尝试了以下查询,但没有成功。

var g = from f in db.Design_Master_Categories
where f.CategoryID == 1
select f.CategoryID;

var v = from h in db.Design_Master_ParentMenus
where h.ParentMenuID == g.FirstOrDefault()
select h.ParentMenuID;

var result = from t in db.Design_Master_TileItem
join c in db.Design_Master_Categories
on t.CategoryID equals c.CategoryID
join p in db.Design_Master_ParentMenus
on c.ParentMenuID equals p.ParentMenuID
where p.ParentMenuID == v.FirstOrDefault()
select t;

但是当我运行程序时,我总是得到 result = null。

最佳答案

如何

    where f.CategoryID == 1

条件如下

Now I want to get all the Items from Master_Design_TileItem whose grandparent's ParentMenuID is equal to 1.

?你说,你想要 ParentMenuID = 1,而不是 CategoryID = 1

你也没有说你的模型是如何设置的,但是有了适当的导航属性,你应该能够做到:

var result = from c in db.Design_Master_Categories
from i in c.TileItems
where c.ParentMenuID == 1
select i;

关于c# - 获取所有祖 parent ID 等于 1 的 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22261794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com