一連のバッチ更新を行うためにEntityFramework.Extendedライブラリを使用しています。私が更新しているテーブルの重要な部分は次のようになります。
CREATE TABLE [dbo].[BoosterTargetLog]
(
[Id] BIGINT NOT NULL identity PRIMARY KEY,
[CustomerUserId] INT NULL,
CookieId uniqueidentifier not null,
CONSTRAINT [FK_BoosterTargetLog_ToOrganizationCookie] FOREIGN KEY (CookieId) REFERENCES [OrganizationCookie]([CookieId])
)
C# 更新コードは次のようになります。
var query = db.BoosterTargetLogs
.Where(x =>
x.OrganizationCookie.OrganizationId == organizationId &&
x.CookieId == cookieId &&
x.CustomerUserId == null);
var updated = await query.UpdateAsync(x => new BoosterTargetLog
{
CustomerUserId = customerUserId
});
これにより、次のような SQL 更新コードが生成されます。
exec sp_executesql N'UPDATE [dbo].[BoosterTargetLog] SET
[CustomerUserId] = @p__update__0
FROM [dbo].[BoosterTargetLog] AS j0 INNER JOIN (
SELECT
[Extent2].[OrganizationId] AS [OrganizationId],
CAST( [Extent1].[Id] AS int) AS [C1]
FROM [dbo].[BoosterTargetLog] AS [Extent1]
INNER JOIN [dbo].[OrganizationCookie] AS [Extent2] ON [Extent1].[CookieId] = [Extent2].[CookieId]
WHERE ([Extent2].[OrganizationId] = @p__linq__0) AND ([Extent1].[CookieId] = @p__linq__1) AND ([Extent1].[CustomerUserId] IS NULL)
) AS j1 ON (j0.[Id] = j1.[Id])',N'@p__linq__0 int,@p__linq__1 uniqueidentifier,@p__update__0 int',@p__linq__0=1075,@p__linq__1='44A191F0-9086-4867-9777-ACEB9BB3B944',@p__update__0=95941
C# コードを使用して更新を実行するか、生成された SQL を手動で実行すると、次のエラーが発生します。
Invalid column name 'Id'.
問題は、生成された SQL にエラーがあることです。次のように書かれている部分に注意してください。
AS j1 ON (j0.[Id] = j1.[Id])
実際には次のようになります。
AS j1 ON (j0.[Id] = j1.[C1])
私の推測では、EntityFramework.Extended ライブラリに何らかのバグがあるということです。
回避策の提案はありますか?