I want to use a value lookup in linq to entities like this:
x => x.Prop1 * values[x.Prop2]
Getting an error because it cannot translate this into a store expression. I guess I could write the values to the db prior to this and use a foreign key lookup but is that the only way around this?
(Too many rows to do this efficiently in linq to objects)
UPDATE: I've added a table to do the look up from on the DB side with a linq query that now looks like this:
var result = anEntityRepository.GroupBySum(
x => x.Prop1 * x.NavigationProperty.Prop2,
g => new { groupedProperty = g.Prop3 }
);
But the linq produced is unnecessarily complex:
SELECT
[Distinct1].[Prop3] AS [Prop3],
[Distinct1].[C1] AS [C1],
(SELECT
SUM([Filter4].[A1]) AS [A1]
FROM ( SELECT
[Filter3].[Prop1] * [Filter3].[Prop2] AS [A1]
FROM ( SELECT [Extent4].[Prop3] AS [Prop3], [Extent4].[Prop1] AS [Prop1], [Extent6].[Prop2] AS [Prop2]
FROM [dbo].[anEntity] AS [Extent4]
LEFT OUTER JOIN [dbo].[NavigationProperty] AS [Extent6] ON [Extent4].[NavigationPropertyId] = [Extent6].[NavigationPropertyId]) AS [Filter3]
WHERE [Distinct1].[Prop3] = [Filter3].[Prop3]
) AS [Filter4]) AS [C2]
FROM ( SELECT DISTINCT
[Filter1].[Prop3] AS [Prop3],
1 AS [C1]
FROM ( SELECT [Extent1].[Prop3] AS [Prop3], [Extent3].[NavigationPropertyId] AS [NavigationPropertyId]
FROM [dbo].[anEntity] AS [Extent1]
))
) AS [Filter1]
) AS [Distinct1]
Would expect it to do a single select statement with a join on the navigation property. Would also like to select multiple properties but it adds another unnecessary select each time. Any ideas on how I can simplify the generated sql?