我似乎无法用正确的选择完成我的 linq 语句。到目前为止,我有以下内容,但问题是当我想要对所有内容进行选择时,它会导致只有 CategoryTypes 的“选择”:
var qwe = dc.LeadTypes
.Include("DataTypes")
.Include("DataTypes.CategoryTypes")
.Where<LeadType>(x => x.Disabled == false)
.SelectMany(x => x.DataTypes)
.Where(x => x.Disabled == false)
.SelectMany(x => x.CategoryTypes)
.Where(x => x.Disabled == false)
.ToList();
生成的 SQL
SELECT
[Extent3].[CategoryTypeID] AS [CategoryTypeID],
[Extent3].[Name] AS [Name],
[Extent3].[DataTypeID] AS [DataTypeID],
[Extent3].[Disabled] AS [Disabled]
FROM [LeadLookup].[LeadType] AS [Extent1]
INNER JOIN [LeadLookup].[DataType] AS [Extent2] ON [Extent1].[LeadTypeID] = [Extent2]. [LeadTypeID]
INNER JOIN [LeadLookup].[CategoryType] AS [Extent3] ON [Extent2].[DataTypeID] = [Extent3].[DataTypeID]
WHERE (0 = [Extent1].[Disabled]) AND (0 = [Extent2].[Disabled]) AND (0 = [Extent3]. [Disabled])
我这样做的原因是因为我在三个表中的每一个上都有一个禁用的列,我不想返回这些行。
谢谢