I have three tables in the database:
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 *---------------
Now I want to get all the elements from Master_Design_TileItemwhose grandparent ParentMenuID is 1.
So far I tried the following queries, but I failed.
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;
But when I run the program, I always get result = null.
source
share