0

I cant seem to finish my linq statement with the correct select. So far I have the following, but the problem is it results in a 'Select' of only the CategoryTypes's, when I want a select on everything:

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();

Resulting 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])

The reason I am doing this is because I have a disabled column on each of the three tables and I do not want to return those rows.

Thanks

4

2 に答える 2

0

include() を使用する場合、列を別の形状に射影することはできません。射影付きの列に同じ名前を付けることはできません。

結果

var qwe = dc.LeadTypes.Where(x => x.Disabled == false)
        .SelectMany(x => x.DataTypes.Where(y => y.Disabled == false), (lead, data) => new
        {
            disabledLeadType = lead.Disabled,
            disabledDataType = data.Disabled,
            idDataType = data.Id,
            categoryType = data.CategoryTypes
        }
        )
        .SelectMany(x => x.categoryType.Where(y => y.Disabled == false), (lead_data, category) => new
        {
        lead_data.disabledLeadType, lead_data.disabledDataType, lead_data.idDataType,
        disabledCategoryType = category.Disabled,
        idCatergoryType = category.Id
        }
        )
        .ToList();
于 2016-04-21T07:04:09.637 に答える