I've a data-structure similar to the following:
我有一个类似于以下的数据结构:
SearchCategories
------------------------------
Id : int
ParentId : int (nullable)
Title : varchar (70)
The ParentId is a foreign key back to the Id on the same table, this allows for an infinitely nested hierarchy of search categories.
ParentId是返回到同一个表上的Id的外键,这允许无限嵌套的搜索类别层次结构。
From there, I have a ContentLinks table:
从那里,我有一个ContentLinks表:
ContentLinks
--------------------------------
Id : int
SearchCategoryId : int
Title : varchar (70)
What I'd like to be able to do is provide a SearchCategory.Id (that has child SearchCategories) and find all ContentLinks that are in the given search category, and in any of it's children using LINQ to SQL.
我希望能够做的是提供一个SearchCategory.Id(具有子SearchCategories)并查找给定搜索类别中的所有ContentLink,以及使用LINQ to SQL的任何子项。
Thanks,
Kieron
谢谢,Kieron
1 个解决方案
#1
1
I don't think it is possible using linq to sql in some easy way. You can always use sql query to be executed directly (how). In sql server you can use Common Table Expression (CTE) to get the data for self join. To get started with CTE you may see here and here
我不认为以某种简单的方式使用linq到sql是可能的。您始终可以使用sql查询直接执行(如何)。在sql server中,您可以使用公用表表达式(CTE)来获取自连接的数据。要开始使用CTE,您可以在这里和这里看到
#1
1
I don't think it is possible using linq to sql in some easy way. You can always use sql query to be executed directly (how). In sql server you can use Common Table Expression (CTE) to get the data for self join. To get started with CTE you may see here and here
我不认为以某种简单的方式使用linq到sql是可能的。您始终可以使用sql查询直接执行(如何)。在sql server中,您可以使用公用表表达式(CTE)来获取自连接的数据。要开始使用CTE,您可以在这里和这里看到