1

「select new」クエリを反映する式ツリーを構築しようとしています。

この質問に対するイーサンの回答を使用しています。一般的なリストではうまく機能しますが、LINQ to Entities では次の例外が発生します。

System.NotSupportedException: Unable to create a constant value of type X.
Only primitive types or enumeration types are supported in this context.

X はクエリを実行しているエンティティです。

デバッガーを使用すると、これは式ツリーを持つ IQueryable です。

SELECT [Extent1].[Id] AS [Id],
       [Extent1].[Nombre] AS [Nombre],
       [Extent1].[Apellido] AS [Apellido]
FROM [dbo].[Empleadoes] AS [Extent1]
.Select(t => new Nombre;String;() {Nombre = t.Nombre})

そして、これは通常のlinq表記を使用したIQueryableです(実際には同じクエリではありませんが、ポイントを取得するために-それらは異なります)

SELECT [Extent1].[Dni] AS [Dni],
       [Extent1].[Nombre] + N' ' + [Extent1].[Apellido] AS [C1]
FROM [dbo].[Empleadoes] AS [Extent1]

どんな助けでも感謝します。ありがとう。

4

1 に答える 1