我在数据库中有三个表:
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 *---------------
现在我想从
Master_Design_TileItem
中获取所有其祖父级的ParentMenuID
等于1的项目。
到目前为止,我尝试了以下查询但没有成功。
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的结果。
v
和g
时,它们将始终为1
。查询语句为:where f.CategoryID == 1 select f.CategoryID
。 - Brad M