Select value from grandchildren

我的梦境 提交于 2020-01-17 09:49:32

问题


I have the following table structure:

I want to select:

  • all TableA entries + the Identifier column from Table C that have:
    • a special value in TableBType ("TableBTypeValue")
    • a special value in TableCType ("TableCTypeValue")

The problem that I have is that the linq queries seem to fail when there are TableA entries that have no TableB entry or if there are TableB entries without a TableC (TableBType and TableCType is mandatory so they don't have that problem).

With SQL this would not be a big problem, but as I am new to linq I could not find the correct way to create this query.


回答1:


I think this is what you are looking for:

from c in db.TableC
where c.TableCType == TableCTypeValue
join b in db.TableB on c.TableBId equals b.Id
where b.TableBType == TableBTypeValue
join a in db.TableA on b.TableAId equals a.Id
select new { a, c.Identifier };

Hope it helps.



来源:https://stackoverflow.com/questions/11925676/select-value-from-grandchildren

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!